2016-10-04 19 views
1

私は3つのフォームのWebサイトを持っていますが、これらのフォームのうち2つだけがSalesforceデータベースに情報を入力する必要があります。フックを使用するフォームとそれを経由しないフォームはどのように定義するのですか?制限連絡フォーム7フック(送信前)特定のフォーム

私が使用しているコードをフォロー:

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 
} 

はあなたの助けをいただき、ありがとうございます。

+0

: 'もし(!$ contact_form->のid == $のmyform_id)を リターン;' しかし、私はPHPについてほとんど知っています。私はこの行にどこに入るべきですか?手伝ってくれませんか? もう一度ありがとうございます。 –

+0

私はこれが好きでした: 'add_action( 'wpcf7_before_send_mail'、 'my_conversion'); 関数my_conversion($ contact_form){ $ title = $ contact_form-> title; $ submission = WPCF7_Submission :: get_instance(); $ id = $ contact_form-> id(); \t \t if($ id == 68){ $ submission-> skip_mail = true; } \t if($ id == 65){ $ posted_data = $ submission-> get_posted_data(); } (...) ' これで、通常、ID = 65のフォームがSalesforceに記録されます。しかし、ID = 68は電子メールを送信せず、入力されたフィールドでロックされています。私は間違って何をしていますか?誰にもアイデアはありますか? –

+0

こんにちは。私は解決策を得ました、私はそれが最高だとは思わないが、ここで私がしたものです: 私は@タカユキスターによって提案されたソリューションを使用しました。 "$ contact_form-> title()"の場合 –

答えて

0

私は解決策を持って、私はそれが最高だと思うけど、ここで私がやったことではありません。

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()"の場合

「フォーム名」は、アクションを実行するフォームの名前で変更してください。

ありがとう@takayukister!私はこの機能を発見した

関連する問題