【发布时间】:2017-02-13 00:49:00
【问题描述】:
我有一个包含 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
}
感谢您的帮助。
【问题讨论】:
-
我找到了这个函数:
if ( $contact_form->id !== $myform_id ) return;但是我对 PHP 知之甚少。我应该在哪里输入这条线?你能帮我吗?再次感谢。 -
我是这样做的:
add_action( 'wpcf7_before_send_mail', 'my_conversion' ); function my_conversion( $contact_form ) { $title = $contact_form->title; $submission = WPCF7_Submission::get_instance(); $id = $contact_form->id(); if ( $id==68 ) { $submission->skip_mail = true; } if ( $id==65 ) { $posted_data = $submission->get_posted_data(); } (...)现在 ID = 65 的形式通常记录在 Salesforce 中。但是 ID = 68 不发送电子邮件,被填充的字段锁定。我究竟做错了什么?有人有什么想法吗? -
你好。我得到了一个解决方案,我认为这不是最好的,但这是我所做的:我使用了@takayukister 建议的解决方案。如果是“$contact_form->title()”。
标签: php wordpress salesforce contact-form-7