I have raised this question on the WP Answers as well. But since this uses Salesforce too, wasn't sure if I'd get a response there.
I am using Contact Fo开发者_Python百科rm 7 on my website and would like to integrate Salesforce lead tracking with it.
I was able to add a hidden field with my oid as suggested on this site
But when I submit the contact form after adding this, it just gets stuck and never actually returns. As soon as I remove the hidden field, it starts working fine.
Has anyone been able to integrate the lead tracking system with Wordpress Contact Form plugins?
I also tried using cform with the instructions provided here. But this gives a warning that fopen failed. I assume thats because fopen does not allow write operations with HTTP wrappers. Not sure how the author managed to get it working!
Would appreciate any help on this! I do not want to use the salesforce Web-to-lead form. Thanks.
From my research into integrating salesforce with cforms the basic principal is that you need the POST info needs to correspond exactly with the cform POST info.
When writing the post you liked to I research the process by using an example form from them - embedded code provided - then found a way to make cforms submit the data, formatted the way they specified to https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8 the url they had in their form.
Feel free to use me if you run into difficulties...
Have you tried following the instructions in this post? It provides the php code you need in your functions.php to integrate Contact Form 7 with Salesforce:
http://daddyanalytics.com/integrating-contact-form-7-and-salesforce/
I spent hours in searching for solution but nothing worked, I tried all recommend solutions e.g. http://daddyanalytics.com/integrating-contact-form-7-and-salesforce/ and http://www.alexhager.at/how-to-integrate-salesforce-in-contact-form-7/ I resolved the issue :)
I also tried plugin https://wordpress.org/plugins/forms-3rdparty-integration/
But nothing worked, then during search someone posted solution with hook wpcf7_mail_components. When I used the code, the code was really working, thanks to that guy. I don't remember the link now. But, my goal then was to make wpcf7_before_send_mail callable and accessible. As it was never been called by the above recommendations.
Then I introduced the last two parameters, i.e.
add_action('wpcf7_before_send_mail', 'my_conversion', 10, 1); //this will call the hook
add_action('wpcf7_before_send_mail', 'my_conversion'); //not calling the hook for me
add_action('wpcf7_before_send_mail', 'my_conversion', 10); //also not calling the hook for me
Please like it if it resolves your issue.
So here is the complete solution:
add_action('wpcf7_before_send_mail', 'my_conversion', 10, 1);
function my_conversion($cf7) {
$email = $cf7->posted_data["email"];
$name = $cf7->posted_data["name"];
$phone = $cf7->posted_data["phone"];
$business_type = $cf7->posted_data["business-type"];
$no_stations = $cf7->posted_data["number-of-stations"];
$lead_source = $cf7->title;
$post_items[] = 'oid=<YOUR-SALES-FORCE-ID>';
$post_items[] = 'name=' . $name;
$post_items[] = 'email=' . $email;
$post_items[] = 'phone=' . $phone;
$post_items[] = 'business_type=' . $business_type;
$post_items[] = 'no_of_stations=' . $no_stations;
$post_items[] = 'lead_source=' . $lead_source;
if (!empty($name) && !empty($phone) && !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
}
}
This is what worked for me, just remember to change “Contact form 1” with the name of the form that you want to perform the action, and put your salesforce business id instead of example one.
add_action( 'wpcf7_before_send_mail', 'my_conversion' );
function my_conversion( $contact_form ) {
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
}
if ( 'Contact form 1' == $title ) {
$email = $posted_data["your-email"];
$name = $posted_data["first-name"];
$last = $posted_data["last-name"];
$phone = $posted_data["tel"];
$company = $posted_data["company-name"];
$company_size = $posted_data["menu-870"];
$post_items[] = 'oid=00vF80000003zx6';
$post_items[] = 'first_name=' . $name;
$post_items[] = 'last_name=' . $last;
$post_items[] = 'email=' . $email;
$post_items[] = 'phone=' . $phone;
$post_items[] = 'company=' . $company;
$post_items[] = '00df800000BypGb=' . $company_size;
$post_string = implode( '&', $post_items );
$ch = curl_init( 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8' );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_string );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_exec( $ch ); // Post to Salesforce
curl_close( $ch ); // close cURL resource
}
}
精彩评论