I have a form with fields like name, email, zipcode, guest name, guest email, guest zipcode. How would I get the "guest" fields to save as a separate lead?
I was directed to http://developers.marketo.com/blog/server-side-form-post/
And this is what I have so far. Would cURL be the best way to do this? and how do I save as 2 leads does marketo have a way of doing this or would I need to write an SQL statement.
<?php
extract($_POST);
$url = 'http://app-x.marketo.com/index.php/leadCapture/save';
$fields = array(
'FirstName' => urlencode($first_name),
'LastName' => urlencode($last_name),
'Email' => urlencode($email),
'PostalCode' => urlencode($postalcode),
'Guest_Last_Name' => urlencode($guest_last_name),
'Guest_Name' => urlencode($guest_first_name),
'Guest_Email_Address' => urlencode($guest_email),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
?>
<form id="theform" action="http://app-x.marketo.com/index.php/leadCapture/save" method="POST">
<input type="hidden" name="munchkinId" value="munchkinId#">
<input type="hidden" name="formid" value="forimd#">
First Name:
<input type="text" name="FirstName">
<br>
Last Name:
<input type="text" name="LastName"><br>
Email Address:
<input type="text" name="Email"><br>
Zip Code:
<input type="text" name="PostalCode"><br>
Colleague First Name:
<input type="text" name="Guest_Last_Name"><br>
Colleague Last Name:
<input type="text" name="Guest_Name"><br>
Colleague Email:
<input type="text" name="Guest_Email_Address"><br>
</form>
I was directed to http://developers.marketo.com/blog/server-side-form-post/
And this is what I have so far. Would cURL be the best way to do this? and how do I save as 2 leads does marketo have a way of doing this or would I need to write an SQL statement.
<?php
extract($_POST);
$url = 'http://app-x.marketo.com/index.php/leadCapture/save';
$fields = array(
'FirstName' => urlencode($first_name),
'LastName' => urlencode($last_name),
'Email' => urlencode($email),
'PostalCode' => urlencode($postalcode),
'Guest_Last_Name' => urlencode($guest_last_name),
'Guest_Name' => urlencode($guest_first_name),
'Guest_Email_Address' => urlencode($guest_email),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
?>
<form id="theform" action="http://app-x.marketo.com/index.php/leadCapture/save" method="POST">
<input type="hidden" name="munchkinId" value="munchkinId#">
<input type="hidden" name="formid" value="forimd#">
First Name:
<input type="text" name="FirstName">
<br>
Last Name:
<input type="text" name="LastName"><br>
Email Address:
<input type="text" name="Email"><br>
Zip Code:
<input type="text" name="PostalCode"><br>
Colleague First Name:
<input type="text" name="Guest_Last_Name"><br>
Colleague Last Name:
<input type="text" name="Guest_Name"><br>
Colleague Email:
<input type="text" name="Guest_Email_Address"><br>
</form>
The solution is pretty simple, you just run through the cURL function twice, first time passing it the 'Email' => urlencode($email)', second time 'Email' => urlencode($guest_email), etc. There's no magic, it's two form posts.
P.S. I also want to note that you aren't validating your input. extract($_POST) offers zero security. (Yes, a point might be made that you are proxying the data straight back to Marketo and it's up to them to validate it, but it is still very poor practice to put user input into global PHP scope.)
Other Questions:
How would an admin be able to select this form?
Will it automatically override the form relating to the form ID?
Where would be the best location to host this cURL function and form?
I don't really understand your questions about "selecting this form" -- where?
Is the initial form (the one that's two forms in one) hosted on your own server?
The initial form was made inside of marketo. Im not sure how the hosting works with that but its not on my own server.
When you do a server-side form post, you're impersonating a browser-side ("client-side") form post. The Marketo server doesn't care whether the data comes in via a browser, or a server language like PHP, or even a custom app you could build in whatever language you want. It just cares that the data looks right: that is, (1) it contains a formID that also exists in Marketo and (2) the fields match up.
Some of the things about your setup aren't quite clear to me. Do you have access to a server on which you are going to place that PHP code? And that PHP-capable server is also the server that receives the form post from your custom form? Please explain in as much detail as you can.
P.S. I might also note that you don't need a server-side form post to do this. You could do it all from the browser if you were using an embedded Marketo form (in the onSuccess handler, change the form fields and then send the form a second time).
In this demo, the form posts once, then switches the First Name and Last Name fields and posts again automatically. How to manipulate other fields is left as an exercise for the reader, as they say.
Hi Sanford,
Don't we need to clean the mkto token in the second submit ?
-Greg
You may want to, yes, but that's an orthogonal issue so I didn't want to make the demo too busy.
You can also submit the secondary email first, then you don't need to worry about it (since the session will be associated with the last submit).
EDIT: I updated the demo to include clearing the Munchkin token value.
Provided the user has JavaScript enabled, any HTML form can post to multiple destinations, or post multiple permutations of its values to the same destination. But it is easier if your forms builder contains such useful callbacks.