• Forbidden
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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
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