• Paul_83uk
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
I have been preparing to move all my forms input across to SF. I have built them all on my test server and they work fine using cURL to POST data to SF. I moved my first form yesterday and it doesn't work. it doesn't throw up any errors just sits on the page running the cURL?

 Any ideas why this would work on one server and not another?

Code below just in case it my code and not a server setting!

Code:
<—php

// SF Org Id.
$oid = "##############";

// Set Return URL if it hasn't been set.
$retURL ="############";

//Set debugging
//$debug = "1";
//$debugEmail = "###########";


// Make sure cURL is enabled
if (!function_exists('curl_init')) {
 error("Curl is not setup on this PHP server and is required for this script");
}


// Process the data that came in from the W2L form

if (isset($_POST)) {
 
 if (count($_POST) == 0) exit("Error.  No data was passed to this script.");
 
 $cleanPOST = array(); // new variable that will hold cleaned up a version of $_POST data
 
 // Loop through the $_POST data and process it
 foreach ($_POST as $key=>$value){
   $cleanPOST[stripslashes($key)] = makeclean($value);
 }

 // Add the Org ID & reyURL if it's not passed into the script from the W2L form
 if (!isset($_POST["oid"])) $cleanPOST["oid"] = $oid;
 if (!isset($_POST["retURL"])) $cleanPOST["retURL"] = $retURL;
 
 //if (!isset($_POST["debug"])) $cleanPOST["debug"] = $debug;
 //if (!isset($_POST["debugEmail"])) $cleanPOST["debugEmail"] = $debugEmail;
 
} else {
 exit("Error.  No data was passed to this script.");
}


// Use cURL to post to Salesforce web to lead 

 // Create a new cURL resource
 $ch = curl_init(); 

 // Set Options
  
  // Point to the Salesforce Web to Lead page
  curl_setopt($ch, CURLOPT_URL, "https://www.salesforce.com/servlet/servlet.WebToLead–encoding=UTF-8");
  
  // Set the method to POST
  curl_setopt($ch, CURLOPT_POST, 1);
  
  // Pass POST data
  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST));
  
 
 curl_exec($ch); // Post to Salesforce
 
 curl_close($ch); // close cURL resource
 
˜>



I am the web developer of a Software Company, we have recently started to use Salesforce.

My understanding of standard web-to-lead is the form has to post to Saleforce website.
I already have a large amount of forms on our website that have a lot of functionality and need to post to within my website. I wanted to be able to grab the leads from these forms quickly and easily while still keeping the functionality that is already in place.

I found an App called FormVester, it seemed ideal for this but I don't think it's supported any longer.

Anyone know of any other way of achieving this?

Ok,
 
I have seen many posts in regards to submitting a custom form to Salesforce and generating a Lead and the Lead Source Details for Google Adwords.
I have taken the time to write a script that will do the trick for you. Let me know if you have any issues with it. See below...
 
Salesforce Fields
------------------------
oid={OID NUMBER}
retURL={CAN BE ANYTHING, JUST HAS TO BE THERE}
lead_source={LEAD SOURCE NAME}
Campaign_ID={CAMPAIGN_ID}
first_name={FIRST NAME}
last_name={LAST NAME}
company={COMPANY NAME}
landing={LANDING PAGE}
referrer={REFERER PAGE}
 
Example:
------------
oid=****&retURL=http//www.mysite.com/thanks.php&lead_source=Web+Referral&Campaign_ID=****&first_name=First&last_name=Last&company=Company&landing=http://www.mysite.com/myform.php&referrer=http://www.mysite.com/myprevpage.php
 
 
 
 
HTML/Javascript Code:
------------------------------
 
Put there two fields in your form (hidden)
---
<input type="hidden" name="landing" id="landing">
<input type="hidden" name="referrer" id="referrer">
 
 
Put this Salesforce code at the bottom of your page directly above the </body> tag
---
<script type="text/javascript" src="https://lct.salesforce.com/sfga.js"></script>
<script type="text/javascript">__sfga();</script>
<script type="text/javascript">
    var parts    = __kvalueOf('__kts').toString().split(',');
    var landing  = parts[1];
    var referrer = parts[2];
    document.getElementById('landing').value  = landing;
    document.getElementById('referrer').value = referrer;
</script>
 
 
PHP Code w/ cURL
-------------------------
<?php
$salesforce_url = 'http://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
$salesforce_data  = 'oid=****&retURL=http//www.mysite.com/thanks.php&lead_source=Web+Referral&Campaign_ID=****';
$salesforce_data .= '&first_name=First&last_name=Last&company=Company';
$salesforce_data .= '&landing=http://www.mysite.com/myform.php&referrer=http://www.mysite.com/myprevpage.php';
 
$salesforce_lead_source_url = 'https://lct.salesforce.com/sfga';
 
if( salesforce_lead($salesforce_url , $salesforce_data) && salesforce_lead_source($salesforce_lead_source_url, $salesforce_data) )
{
    #redirect to thank you page
    header("Location: thanks.php");
    exit;
}
else
{
    print('Error');
    exit;
}
 
Function salesforce_lead($url, $data)
{
    #submit to salesforce as lead
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $auth_result = curl_exec($ch);
    if( curl_errno($ch) ) //error
    {   
        print( curl_error($ch) );
        return false; 
    }
    else // success
    { 
        curl_close($ch);
        return true;
    }
}
 
Function salesforce_lead_source($url, $data)
{
    $t = timeAndMilliseconds();
    $r = $_POST['referrer'];
    $l = $_POST['landing'];
    $oid = '****';
 
    $sfga  = 't='.$t.'&r='.$r.'&l='.$l.'&oid='.$oid.'&ts='.$t.'&rs='.$r.'&ls='.$l;
    $sfga .= '&url='.urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
    $sfga .= '&customForm=true&method=post&retURL='.urlencode('http://'.$_SERVER['HTTP_HOST'].'/newsletter-sign-up-thank-you.htm');
 
    #append sfga to the data that was previously submitted to salesforce
    $data .= '&sfga='.$sfga;
 
    #submit to salesforce as lead source to attach to lead
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $auth_result = curl_exec($ch);
    if( curl_errno($ch) ) //error
    {   
        print( curl_error($ch) );
        return false; 
    }
    else // success
    { 
        curl_close($ch);
        return true;
    }
}
 
Function timeAndMilliseconds()
{
    list($usec, $sec) = explode(" ",microtime());
    return (((float)$usec/1000) + (float)$sec);
}
?>


Message Edited by Forbidden on 08-07-2008 07:55 AM

Message Edited by Forbidden on 08-07-2008 09:11 AM

Message Edited by Forbidden on 08-11-2008 05:10 AM
I am the web developer of a Software Company, we have recently started to use Salesforce.

My understanding of standard web-to-lead is the form has to post to Saleforce website.
I already have a large amount of forms on our website that have a lot of functionality and need to post to within my website. I wanted to be able to grab the leads from these forms quickly and easily while still keeping the functionality that is already in place.

I found an App called FormVester, it seemed ideal for this but I don't think it's supported any longer.

Anyone know of any other way of achieving this?