Skip to content

Commit

Permalink
Merge pull request #1 from lassodatasystems/example-submitter
Browse files Browse the repository at this point in the history
Added support for phone, address and questions
  • Loading branch information
trb committed Feb 27, 2016
2 parents a83635e + 0e2eb8d commit 007ac19
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
registrant-submitter-php.iml
55 changes: 55 additions & 0 deletions lead.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"firstName":"Test",
"lastName":"Registrant",
"clientId":"",
"projectIds":[""],
"emails":[
{
"email":"test_reg@mylasso.com",
"type":"Home",
"primary":true
}
],
"phones":[
{
"phone":"123 456 7890",
"type":"Mobile",
"primary":true
}
],
"notes":["This is a test note"],
"rating":"N",
"sourceType":"Online Registration",
"addresses":[
{
"address":"350 Fifth Avenue",
"city":"New York",
"country":"USA",
"province":"NY",
"postalCode":"NY",
"type":"Home",
"primary":true
}
],
"questions":[
{
"id":1,
"path":"",
"name":"t-bar",
"answers":[

]
},
{
"id":0,
"path":"projectname/survey/",
"name":"do you like us?",
"answers":[
{
"id":"x",
"text":"Yes"
}
]
}
]
}
52 changes: 42 additions & 10 deletions signup.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
<html>

<!--
This is an example registration page.
shown here is the usage of javascript to submit
to a local backend for relaying to Lasso
The ajax request can be removed and regular form submittion
can be used in its place.
Please keep your LassoUid Private, do not put it on your form.
-->

<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
<script type = 'text/javascript'>
var register = function() {
var first_name = document.getElementById('first_name').value;
var last_name = document.getElementById('last_name').value;
var email = document.getElementById('email').value;

jQuery.ajax({
type: "POST",
url: 'http://app.andrew.mylasso.com/registration/signup.php',
data: {
firstName: first_name,
lastName: last_name,
email: email
firstName: document.getElementById('first_name').value,
lastName: document.getElementById('last_name').value,
email: document.getElementById('email').value,
phone: document.getElementById('phone').value,
address: document.getElementById('address').value,
city: document.getElementById('city').value,
province: document.getElementById('province').value,
postal: document.getElementById('postal').value,
country: document.getElementById('country').value
},
success: function(arguments){
console.log(arguments);
Expand All @@ -24,14 +41,29 @@
</head>
<body>
<div>
First Name:<input type='text' id='first_name' value="Test"></input>
First Name:<div><input type='text' id='first_name' value="Test"></input></div>
</div>
<br />
<div>
Last Name:<div><input type='text' id='last_name' value="Registrant"></input></div>
</div>
<br />
<div>
Email:<div><input type='text' id='email' value="test_reg@mylasso.com"></input></div>
</div>
<br />
<div>
Last Name:<input type='text' id='last_name' value="Registrant"></input>
Phone:<div><input type='text' id='phone' value="123 456 7890"></input></div>
</div>
<br />
<div>
Email:<input type='text' id='email' value="test_registrant@mylasso.com"></input>
Address:<div><input type='text' id='address' value="350 Fifth Avenue"></input></div>
City:<div><input type='text' id='city' value="New York"></input></div>
Province:<div><input type='text' id='province' value="NY"></input></div>
Postal Code:<div><input type='text' id='postal' value="10118"></input></div>
Country:<div><input type='text' id='country' value="USA"></input></div>
</div>
<br />
<div>
<button onClick="register()">Register</button>
</div>
Expand Down
63 changes: 42 additions & 21 deletions signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,56 @@
require('src/LassoLead.php');
require('src/RegistrantSubmitter.php');

/* These variables should only be attached to the request on the server side */
$clientId = 19;
$projectId = 6;
/*
* These variables should only be attached to the request on the server side
*/
$clientId = '';
$projectId = '';

/* This is a security token and should be kept private
* this should not be a hidden field on your registration page.
/*
* This is a security token and should be kept private and should not be a
* hidden field on your registration page
*/
$lassoUid = '';
$apiKey = '';

if (empty($clientId) || empty($projectId) || empty($apiKey)) {
throw new Exception('Required parameters are not set, please
check that your $clientId, $projectId and $apiKey are
configured correctly');
}

/* Contructing and submitting a lead */
/*
* Constructing and submitting a lead:
* Map your forms fields into the lead object and submit
*/
$lead = new LassoLead($_REQUEST['firstName'],
$_REQUEST['lastName'],
$projectId,
$clientId,
$lassoUid);
$_REQUEST['lastName'],
$projectId,
$clientId);
$lead->addEmail($_REQUEST['email']);
$lead->setRating('MrNew');
$lead->addPhone($_REQUEST['phone']);
$lead->addAddress($_REQUEST['address'],
$_REQUEST['city'],
$_REQUEST['province'],
$_REQUEST['postal'],
$_REQUEST['country']);
$lead->setRating('N');
$lead->addQuestion('\TheProject\Registration', 'How Heard', 'Newsletter');

$submitter = new RegistrantSubmitter();
$curl = $submitter->submit('http://api.andrew.mylasso.com/registrants', $lead, 'L32rnSAF0');
$curl = $submitter->submit('http://api.mylasso.com/registrants', $lead, $apiKey);

// Example, reading the error codes returned by the submission processor
// CURLOPT_FOLLOWLOCATION - set false to disable redirection
/*
* ---------------------------------------------------------------
* Troubleshooting examples
* ---------------------------------------------------------------
*/

// Viewing the submission body
#echo json_encode($lead->toArray());
/* Viewing the submission body */
//echo json_encode($lead->toArray());

// Getting the response servers response code
#echo curl_getinfo($curl, CURLINFO_HTTP_CODE);
/* Getting the response servers response code */
//echo curl_getinfo($curl, CURLINFO_HTTP_CODE);

// Getting all details of the cUrl request
print_r(curl_getinfo($curl));
/* Getting all details of the cUrl request */
//print_r(curl_getinfo($curl));
Loading

0 comments on commit 007ac19

Please sign in to comment.