doqrt26664 2015-09-22 03:31
浏览 42
已采纳

在PHP中获取联系表格7表格ID

I'm using contact form 7 to load two different forms into a page and then, in addition to sending the email, dynamically adding that information to a database. Unfortunately, because of the plugin, I can't simply just create all inputs with different names to avoid needing a filter. So, essentially, I'd like to pull the form ID into the action hook and dynamically create the $data variable based on which form is being submitted, but I'm not sure how to get the cf7 form ID. Does anyone know how to accomplish this, or perhaps a more feasible way of doing it?

Form Shortcodes

[contact-form-7 id="221" title="Reg 1"] [contact-form-7 id="112" title="Reg 2"]

PHP Action Hook in functions.php

function save_form( $wpcf7 ) {


global $wpdb;

   $form_to_DB = WPCF7_Submission::get_instance();

   if($form_to_DB) {
       $formData = $form_to_DB->get_posted_data(); 
   }

   if("Request a Free Demo" != $formData['demo_request'][0]){
   $freeDemo = "yes";}else { $freeDemo = "nope";}

   if(THE FORM ID = 221) {
   $data = array(
          some values from the 112 form
      $wpdb->insert( $wpdb->prefix . 'registrations', $data );
   );
   }elseif(THE FORM ID = 112) {
     $data = array(
          some other values from the 112 form
   $wpdb->insert( $wpdb->prefix . 'registrations_2', $data );
   );
   }



}
remove_all_filters('wpcf7_before_send_mail');
add_action('wpcf7_before_send_mail', 'save_form' );
  • 写回答

5条回答 默认 最新

  • duancao1951 2015-09-28 21:38
    关注

    SOLVED:

    I wound up just using a logical operator to check if a form specific field was empty or not. If the field "form_2_name" was empty when a form was submitted, then we know that form 1 is being submitted. Simple if statement with that logic did the trick!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改