CF7有一个有用的挂钩wpcf7_submit
可用于处理发送的数据:
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\')
);
}
如果您想在发送电子邮件之前处理数据,这里还有一个钩子:
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 );
还应考虑与提交验证相关的问题,这些问题也涉及此过程。
下面是List of available CF7 hooks»
了解GDPR隐私合规方面的影响。