限制联系表格7挂钩(发送前)到特定表格

时间:2016-10-04 18:28:08

标签: php wordpress salesforce contact-form-7

我有一个包含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
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我得到了一个解决方案,我认为这不是最好的,但这就是我所做的:

if(number[i] < min_value)

我使用了@takayukister建议的解决方案。如果是“$ contact_form-&gt; title()”。

请记住改变&#34; FORM NAME&#34;使用您要执行操作的表单的名称。

谢谢@takayukister!