($_POST['first-name']), 'last_name' => ($_POST['last-name']), 'phone' => ($_POST['phone']), 'email' => ($_POST['your-email']), 'street' => ($_POST['street']), 'city' => ($_POST['city']), 'state' => ($_POST['state']), 'zip' => ($_POST['zip']), 'member_status' => $member_status, 'Campaign_ID' => $Campaign_ID, 'oid' => $oid, 'lead_source' => $lead_source, 'Custom_Field_1__c' => ($_POST['CustomField1']), 'Custom_Field_2__c' => ($_POST['CustomField2']), 'Custom_Field_3__c' => ($_POST['CustomField3']), 'Custom_Field_4__c' => ($_POST['CustomField4']) ); foreach ($cleanPOST as $key=>$value){ $cleanPOST[stripslashes($key)] = stripslashes($value); } // Once the POST data is in an array we can send it to Salesforce. //Add a return URL to the data sent which then redirects the user to that URL. // You could do the redirect in the PHP file itself $ch = curl_init(); if (curl_error($ch) != "") { exit( "Error: $error\n"); } curl_setopt($ch, CURLOPT_URL, "https://webto.salesforce.com/servlet/servlet.WebToLead"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST)); // DEBUG use this to see the variables as it is run //error_log(__METHOD__ . http_build_query($cleanPOST)); //error_log(__FUNCTION__ . "\n" . print_r($_POST, 1)); //ob_start(); //var_dump($_POST); //error_log(basename(__FILE__) . "\n" . ob_get_clean()); curl_exec($ch); curl_close($ch); } /** * Function postFiveNine * Send the form data to Five9 so that the call can be made * */ function postFiveNine() { $Campaign_ID = '701130000026vNy'; date_default_timezone_set('America/New_York'); $F9Date = date("Y-m-d")."-". date("H:i"); $F9domain = "connect america"; $FORM_ID = ($_POST['form_ID']); $FORM_order_request = 441; $FORM_brochure_request = 165; $FORM_caregiver_request = 522; $FORM_FirstStreet_request = "FirstStreet"; $FORM_CrispMarketing_request = "CrispMarketing"; $FORM_EmergencyMA_request = "EmergencyMA"; $FORM_FlatironMedia_request = "FlatironMedia"; $FORM_LittleBrookeMedia_request = "LittleBrookeMedia"; $FORM_Covalent_request = "Covalent"; $FORM_FlexMG_request = "FlexMG"; $FORM_SkyRocket_request = "SkyRocket"; $FORM_Walgreens_f9 = "WalgreensReadyResponsef9"; $FORM_Modernize = "modernize"; switch ($FORM_ID) { case $FORM_FirstStreet_request : $F9list = "FirstStreet"; break; case $FORM_CrispMarketing_request : $F9list = "Affiliates"; break; case $FORM_EmergencyMA_request : $F9list = ""; break; case $FORM_FlatironMedia_request : $F9list = "TestEmailtoCampaign"; break; case $FORM_LittleBrookeMedia_request : $F9list = "LittleBrook"; break; case $FORM_Covalent_request : $F9list = "Covalent"; break; case $FORM_FlexMG_request : $F9list = "FlexMG"; break; case $FORM_Walgreens_f9 : $F9list = "Web Form Submissions H"; break; case $FORM_SkyRocket_request : $F9list = "Web Form Submissions H"; break; case $FORM_IdealComparison : $F9list = "Web Form Submissions H"; break; case $FORM_Modernize : $F9list = "Outbound Web Leads"; break; default: //$F9list = "TestEmailtoCampaign"; // enable for testing $F9list = "Web Form Submissions L"; } $newphone = preg_replace('/^1|\D/', '', $_POST['phone']); if(($_POST['dynamic-five9list'])) $F9list = ($_POST['dynamic-five9list']); if(($_POST['dynamic-campaign-id'])) $Campaign_ID = ($_POST['dynamic-campaign-id']); $cleanPOST = array( 'first_name' => ($_POST['first-name']), 'last_name' => ($_POST['last-name']), 'number1' => $newphone, 'F9domain' => $F9domain, 'F9list' => $F9list, 'salesforce_id' => $Campaign_ID, 'Device_6' => $title, 'WebDialer_Key' => $F9Date, 'F9key' => WebDialer_Key, 'F9CallASAP' => true ); foreach ($cleanPOST as $key=>$value){ $cleanPOST[stripslashes($key)] = stripslashes($value); } $ch = curl_init(); // DEBUG - this should return a message to the user it failed if (curl_error($ch) != "") { echo "Error: $error\n"; } curl_setopt($ch, CURLOPT_URL, "https://api.five9.com/web2campaign/AddToList"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST)); curl_exec($ch); curl_close($ch); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // // // // Function postReturn URL // // // // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ function postReturnURL( ) { $FORM_ID = ($_POST['form_ID']); // Define form_id from Widget $FORM_Alert365_request = "Alert365"; $FORM_EmergencyMA_request = "EmergencyMA"; $FORM_EmergencyMA_request = "EmergencyMA"; switch ($FORM_ID) { case $FORM_Alert365_request : header("Location:http://alert365.com/ThankYou.html"); // Alert365 Retun URL break; case $FORM_Walgreens_f9 : header("Location:https://www.walgreensreadyresponse.com/"); // Alert365 Retun URL break; case $FORM_Walgreens_sf : header("Location:https://www.walgreensreadyresponse.com/"); // Alert365 Retun URL break; case $FORM_EmergencyMA_request : header("Location:http://emergency.medicalalert.com/ThankYou.html"); // EmergencyMA Retun URL break; default: //$F9list = "TestEmailtoCampaign"; // enable for testing header("Location:https://medicalalert.com"); // All other Requests } // end switch // Once the POST data is in an array we can send it to Five9. Add a return URL to the data // sent which then redirects the user to that URL. // You could do the redirect in the PHP file itself // Create a new cURL resource $ch = curl_init(); // DEBUG - this should return a message to the user it failed //if (curl_error($ch) != "") { // echo "Error: $error\n"; //} // Point to the Five9 Web to Lead page //curl_setopt($ch, CURLOPT_URL, "http://api.five9.com/web2campaign/AddToList"); // Set the method to POST //curl_setopt($ch, CURLOPT_POST, 1); // this will prevent curl from sending back a retrun page. //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Pass POST data //curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($cleanPOST)); // Debug - uncomment this to see the contents of the variable in the error logs //error_log(__METHOD__ . http_build_query($cleanPOST)); //error_log(__FUNCTION__ . "\n" . print_r($_POST, 1)); //ob_start(); //var_dump($_POST); //error_log(basename(__FILE__) . "\n" . ob_get_clean()); // Post to Five9 curl_exec($ch); // close cURL resource curl_close($ch); // should not need this but maybe the rc value will clear the issue. } postSalesforce(); postFiveNine(); postReturnURL(); ?>