Recently our company began a trial of Salesforce.com. In doing so we opted not to layout the cash for the program that gives you full API access (at the moment any ways). I needed a way to push leads into the system. They have a standard web-to-lead process that requires a form submission and then post back to return URL. I already had a lot of forms that I was using to capture data. Instead of reworking all my forms, I just created a way to post to the Salesforce web-to-lead form from the server side.
I started by creating a basic function which passes in the data I want to capture and pushes it to the Sales force form.
function add_to_salesforce($source, $name, $email, $company, $city, $state, $zip, $phone, $description, $street = "")
{
// simple way of breaking apart the name
$names = split(" ", $name);
//set POST variables
$url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8′;
$fields = array(
'last_name'=>urlencode($names[1]),
'first_name'=>urlencode($names[0]),
'street'=>urlencode($street),
'city'=>urlencode($city),
'state'=>urlencode($state),
'zip'=>urlencode($zip),
'company'=>urlencode($company),
'description'=>urlencode($description),
'email'=>urlencode($email),
'phone'=>urlencode($phone),
'mycustomefieldid' => urlencode($source), // custom field
'oid' => 'youridgoeshere', // insert with your id
'retURL' => urlencode('http://www.yourreturnurl.com'), // sending this just in case
'debug' => '1′,
'debugEmail' => urlencode("
[email protected]"), // your debugging email
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Once that was setup all I had to do was call the function (which I wrapped in a class with something like this:
$myclass = new Myclass;
$myclass->add_to_salesforce("Contact Page", $name, $email_address, $company, "", "", "", $phone, $enquiry);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Works like a charm so far. If you’ve got a slicker way of perfoming this operation, let me know, I’d love to learn how you did it.
Technorati Tags:
Salesforce PHP Programming
Recent comments
24 weeks 4 days ago
30 weeks 1 day ago
30 weeks 1 day ago
30 weeks 1 day ago
30 weeks 2 days ago
30 weeks 2 days ago
30 weeks 2 days ago
38 weeks 1 day ago
39 weeks 15 hours ago
39 weeks 22 hours ago