首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将联系人表格7数据保存到自定义表中

将联系人表格7数据保存到自定义表中
EN

WordPress Development用户
提问于 2020-12-04 17:55:08
回答 1查看 2.4K关注 0票数 0

我需要将联系人表单7数据保存在自定义表中,因为联系人表单CFDB7将信息保存在同一个colum中。

某个插件如何制作这个插件,或者可能是一个php函数呢?

EN

回答 1

WordPress Development用户

发布于 2020-12-05 01:49:57

CF7有一个有用的钩子wpcf7_submit,可以用来处理发送的数据:

代码语言:javascript
复制
add_action("wpcf7_submit", "SE_379325_forward_cf7", 10, 2);

function SE_379325_forward_cf7($form, $result) {
  if( !class_exists('WPCF7_Submission') )
    return;
  $submission = WPCF7_Submission::get_instance();
  if ($result["status"] == "mail_sent") { // proceed only if email has been sent 
    $posted_data = $submission->get_posted_data();
    save_posted_data($posted_data);
  }
};

// your insert function:
function save_posted_data($posted_data){
  //var_dump($posted_data); // $posted_data is an array containing all the form fields and values 
  $form_id = $posted_data["_wpcf7"]; // this is the post->ID of the submitted form so if you have more than one you can decide whether or not to save this form fields
  if($form_id !=2) // for exampe you may want to use only data coming from form # id 2
    return;
  global $wpdb;

  $wpdb->insert( 
     $wpdb->prefix.'{YOUR_TABLE}',
     array(
       '{column1}'=>$posted_data['your-name'],
       '{column2}'=>$posted_data['your-surname']
     ),
     array('%s','%s')
   );
} 

如果您想在发送电子邮件之前处理数据,下面是另一个钩子:

代码语言:javascript
复制
function action_wpcf7_before_send_mail( $contact_form ) { 
  // var_dump($contact_form);
};

add_action( 'wpcf7_before_send_mail', 'action_wpcf7_before_send_mail', 10, 1 ); 

还审议也涉及到这一进程的关于提交的审定问题。

下面是一个可用CF7钩子列表

注意在遵守GDPR隐私方面的影响。

票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/379325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档