将联系表格 7 挂钩(发送前)限制为特定表格
Limit Contact Form 7 hook (Before Send) to specific form
我的网站有 3 个表单,但其中只有两个表单必须将信息输入到 Salesforce 数据库中。我如何定义哪些表单应该使用挂钩,哪些表单应该不通过挂钩?
按照我使用的代码进行操作:
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();
}
$email = $posted_data["your-email"];
$name = $posted_data["your-name"];
$last = $posted_data["your-lastname"];
$phone = $posted_data["tel-71"];
$description = $posted_data["your-message"];
$post_items[] = 'oid=00D4000000xxxxx';
$post_items[] = 'first_name=' . $name;
$post_items[] = 'last_name=' . $last;
$post_items[] = 'company=';
$post_items[] = 'email=' . $email;
$post_items[] = 'phone=' . $phone;
$post_items[] = 'description=' . $description;
$post_items[] = '00N4000000XXXX=' . "Shopping";
$post_items[] = '00N4000000xxxxxx=' . "1";
$post_items[] = 'external=1';
$post_items[] = 'lead_source=Shopping';
$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
}
感谢您的帮助。
我找到了解决方案,我认为这不是最好的,但这是我所做的:
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 ( 'FORM NAME' == $title ) {
$email = $posted_data["your-email"];
$name = $posted_data["your-name"];
$last = $posted_data["your-lastname"];
$phone = $posted_data["tel-71"];
$description = $posted_data["your-message"];
$post_items[] = 'oid=00D4000000xxxxx';
$post_items[] = 'first_name=' . $name;
$post_items[] = 'last_name=' . $last;
$post_items[] = 'company=';
$post_items[] = 'email=' . $email;
$post_items[] = 'phone=' . $phone;
$post_items[] = 'description=' . $description;
$post_items[] = '00N4000000XXXX=' . "Shopping";
$post_items[] = '00N4000000xxxxxx=' . "1";
$post_items[] = 'external=1';
$post_items[] = 'lead_source=Shopping';
$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
}
我使用了@takayukister 建议的解决方案。如果“$contact_form->title()”.
请记住将 "FORM NAME" 更改为您要执行操作的表单名称。
谢谢@takayukister!
我的网站有 3 个表单,但其中只有两个表单必须将信息输入到 Salesforce 数据库中。我如何定义哪些表单应该使用挂钩,哪些表单应该不通过挂钩?
按照我使用的代码进行操作:
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();
}
$email = $posted_data["your-email"];
$name = $posted_data["your-name"];
$last = $posted_data["your-lastname"];
$phone = $posted_data["tel-71"];
$description = $posted_data["your-message"];
$post_items[] = 'oid=00D4000000xxxxx';
$post_items[] = 'first_name=' . $name;
$post_items[] = 'last_name=' . $last;
$post_items[] = 'company=';
$post_items[] = 'email=' . $email;
$post_items[] = 'phone=' . $phone;
$post_items[] = 'description=' . $description;
$post_items[] = '00N4000000XXXX=' . "Shopping";
$post_items[] = '00N4000000xxxxxx=' . "1";
$post_items[] = 'external=1';
$post_items[] = 'lead_source=Shopping';
$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
}
感谢您的帮助。
我找到了解决方案,我认为这不是最好的,但这是我所做的:
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 ( 'FORM NAME' == $title ) {
$email = $posted_data["your-email"];
$name = $posted_data["your-name"];
$last = $posted_data["your-lastname"];
$phone = $posted_data["tel-71"];
$description = $posted_data["your-message"];
$post_items[] = 'oid=00D4000000xxxxx';
$post_items[] = 'first_name=' . $name;
$post_items[] = 'last_name=' . $last;
$post_items[] = 'company=';
$post_items[] = 'email=' . $email;
$post_items[] = 'phone=' . $phone;
$post_items[] = 'description=' . $description;
$post_items[] = '00N4000000XXXX=' . "Shopping";
$post_items[] = '00N4000000xxxxxx=' . "1";
$post_items[] = 'external=1';
$post_items[] = 'lead_source=Shopping';
$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
}
我使用了@takayukister 建议的解决方案。如果“$contact_form->title()”.
请记住将 "FORM NAME" 更改为您要执行操作的表单名称。
谢谢@takayukister!