Sales Force Web to Lead With Existing PHP File

Published by Toronto Mike on February 24, 2009 @ 15:10 in Technology

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...

Permalink Entry Permalink Comments 10 comments

10 Responses to "Sales Force Web to Lead With Existing PHP File"

Mike
June 1, 2009 / 15:23

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

Toronto Mike
June 1, 2009 / 15:29

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
// =======================================

chris
October 7, 2009 / 16:42

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

Toronto Mike
October 7, 2009 / 17:06

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

chris
October 7, 2009 / 17:06

nevermind...just take out the hidden field!

Keith
December 1, 2009 / 16:48

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

Mike Vardy
July 21, 2010 / 22:54

$data = $_POST;

Felix
July 24, 2011 / 16:22

I wrapped this up as a reusable "library":
https://github.com/felixmiddendorf/web2lead

Leave a Reply



« Cocaine Looks and Sounds Awesome Game Two Tonight »