Last active
September 20, 2016 00:22
-
-
Save vimes1984/32be35f4607ba6f8b64e to your computer and use it in GitHub Desktop.
this is an update to this function which is a little outdated now: http://daddyanalytics.com/integrating-contact-form-7-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
<?php | |
/** | |
* Sales force integration | |
*/ | |
add_action( 'wpcf7_before_send_mail', 'my_conversion' ); | |
function my_conversion( $cf7 ){ | |
ob_start(); // start buffer capture | |
$submission = WPCF7_Submission::get_instance(); | |
if ( $submission ) { | |
$posted_data = $submission->get_posted_data(); | |
$email = $posted_data["your-email"]; | |
$first_name = $posted_data["first-name"]; | |
$last_name = $posted_data["last-name"]; | |
$phone = $posted_data["phone"]; | |
$post_items[] = 'oid=<YOU OID HERE>'; | |
$post_items[] = 'first_name=' . $first_name; | |
$post_items[] = 'last_name=' . $last_name; | |
$post_items[] = 'email=' . $email; | |
$post_items[] = 'phone=' . $phone; | |
$form_name = $cf7->name(); | |
$form_id = $cf7->id(); | |
//This checks the form ID so you can use custom fields | |
if ($form_id == 129) { | |
$post_items[] = 'company=' . $posted_data["company"]; | |
$post_items[] = 'URL=' . $posted_data['website']; | |
$post_items[] = '00NA0000007HGfa=' . $posted_data['change']; | |
$post_items[] = '00NA0000007HGg0=' . $posted_data['sales']; | |
$post_items[] = '00NA0000007HGg4=' . $posted_data['employs']; | |
$post_items[] = '00NA0000007HGgE=' . $posted_data['urgency']; | |
$post_items[] = '00NA0000000UpU4=' . $posted_data['want']; | |
$post_items[] = '00NA0000007HSCO=' . $posted_data['comments']; | |
foreach ($posted_data['changeby'] as $key => $value) { | |
# code... | |
switch ($value) { | |
case 'Reading books and implementing the ideas': | |
# code... | |
$post_items[] = '00NA0000007HGgK=' . $value; | |
break; | |
case 'Attending seminars': | |
# code... | |
$post_items[] = '00NA0000007HGgK=' . $value; | |
break; | |
case 'Working with consultants regularly': | |
# code... | |
$post_items[] = '00NA0000007HGgK=' . $value; | |
break; | |
case 'None: I\'m too busy working': | |
# code... | |
$post_items[] = '00NA0000007HGgK=' . $value; | |
break; | |
default: | |
# code... | |
break; | |
} | |
} | |
}elseif ($form_id == 280) { | |
# code... | |
$post_items[] = '00NA0000007HSCO=' . $posted_data['your-subject']; | |
$post_items[] = 'description=' . $posted_data['your-message']; | |
} | |
if(!empty($first_name) && !empty($last_name) && !empty($email) ){ | |
$post_string = implode ('&', $post_items); | |
// Create a new cURL resource | |
$ch = curl_init(); | |
if (curl_error($ch) != ""){ | |
// error handling | |
} | |
$con_url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8'; | |
curl_setopt($ch, CURLOPT_URL, $con_url); | |
// Set the method to POST | |
curl_setopt($ch, CURLOPT_POST, 1); | |
// Pass POST data | |
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_string); | |
curl_exec($ch); // Post to Salesforce | |
curl_close($ch); // close cURL resource | |
} | |
//var_dump($post_items); | |
//var_dump($form_id); | |
} | |
//error_log can e found under wp-content this is being left in becuase this function is a fucker all in all | |
//WP_DEBUG needs to be set to true as does WP_DEBUG_LOG | |
/* | |
DUMP THESE IN YOUR wp-config.php file | |
define('WP_DEBUG', true); | |
define('WP_DEBUG_LOG', true); | |
*/ | |
$contents = ob_get_contents(); // put the buffer into a variable | |
ob_end_clean(); // end capture | |
error_log($contents); // Write to wp-content/debug.log (enable debug mode to see it). | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works fine ! Thanks