Created
August 16, 2011 15:09
-
-
Save jackreichert/1149324 to your computer and use it in GitHub Desktop.
Integrate cforms II and Salesforce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function my_cforms_action($cformsdata) { | |
$formID = $cformsdata['id']; | |
$form = $cformsdata['data']; | |
$curl_connection = curl_init('https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8'); | |
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); | |
curl_setopt($curl_connection, CURLOPT_USERAGENT, | |
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); | |
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); | |
foreach ( $form as $key => $value) { | |
if ($key[1] == '$'){ | |
unset($form[$key]); | |
} else { | |
if ($key=='Campaign_ID') { | |
$post_items[] = $key . '=' . $value; | |
} else { | |
$post_items[] = str_replace(' ','_', strtolower($key)) . '=' . $value; | |
} | |
} | |
} | |
$post_string = implode ('&', $post_items); | |
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); | |
$result = curl_exec($curl_connection); | |
curl_close($curl_connection); | |
$opts = array('http' => | |
array( | |
'method' => 'POST', | |
'header' => 'Content-type: text/html; charset=UTF-8', | |
'content' => $form | |
) | |
); | |
$context = stream_context_create($opts); | |
$fp = fopen('https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8', 'r+', false, $context); | |
fpassthru($fp); | |
fclose($fp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment