Sales Force Web to Lead With Existing PHP File

questionmarkI'm working on a SalesForce.com web-to-lead implementation. In a nutshell, the content submitted via an HTML form needs to auto-update a new instance of SalesForce.com.

I thought it would be straight forward after reading these website setup instructions but I can't get it to work. The issue I'm having is with my existing PHP file that drives the forms. the Web-to-Lead only updates SF when the form action is equal to https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8. When the form action is equal to my PHP file, it doesn't work!

Yes, I've already posted in the SF community forums, but I thought I'd try my luck here. Just in case...


Share this entry

Comments (10 - click here to join in!)



Mike

I am having the same problem. Can you help me out please.
Ihave a php form which inserts to mysql DB and also emails it out. To this, I added my salesforce input fields to post to salesforce using the action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" in the form. This posts to salesforce, but entirely skips the post to the sql database. All my code is in the same file. Please help

June 1, 2009 @ 3:23 PM

Toronto Mike

In the PHP:

// =======================================
// START SALESFORCE SUBMISSION
// =======================================
define('OID', '123456789');
define('SF_URL', 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8');

$ch = curl_init(SF_URL);
$data = $_POST;
unset($data['submitbutton']);
unset($data['postpage']);

$data['oid'] = OID;
$data['sfga'] = '';
$data['123456789'] = $_SERVER['REMOTE_ADDR'];

foreach($data as &$item) {
$item = stripslashes($item);
}

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

$result = curl_exec($ch);
if( $result === false ) {
echo 'Error: '.curl_error($ch).PHP_EOL;
}
curl_close($ch);
// =======================================
// END SALESFORCE SUBMISSION
// =======================================

June 1, 2009 @ 3:29 PM

chris

Hi,

I'm new to this salesforce thing myself.

I'm trying to figure out how to NOT utilize the retURL field.

I'd ultimately like to just post the form to salesforce without redirecting.

Is this possible? If I leave out a value for retURL it just reloads the page. Would rather it not do anything.

thanks

October 7, 2009 @ 4:42 PM

Toronto Mike Verified as the defacto Toronto Mike

Can you self reference the page - so the retURL is the URL of the form itslef?

October 7, 2009 @ 5:06 PM

chris

nevermind...just take out the hidden field!

October 7, 2009 @ 5:06 PM

Keith

Toronto Mike,
I am trying to setup a php script to submit fields for the web-to-lead function from Salesforce as well. I am not a web developer but can hack some things together as needed. I see your sample of the php setup you used but am not sure where it references items like:
input id="first_name"
input id="title"
input id="last_name"

etc.

Any help would be much appreciated.

Thanks,
Keith

December 1, 2009 @ 4:48 PM

Mike Vardy

$data = $_POST;

July 21, 2010 @ 10:54 PM


Leave a comment


Only 10 comments? C'mon, we can do better... Leave a comment above and let's keep this conversation going!


« Cocaine Looks and Sounds Awesome Game Two Tonight »