當我想一個形式保存一些特殊的數據,加工到CRM,或只是重定向我的所有形式,我用的是聯繫表格7鉤:wpcf7_before_send_mail
下面是一個例子,以任何形式重定向到一個頁面(摘自我已經做了一個實用插件,所以,不要關心未設置和會話線,選項......)。
add_action('wpcf7_before_send_mail', 'mail_send_redirection');
function mail_send_redirection($contactform){
$submission = WPCF7_Submission::get_instance();
if($options['_redirect_all_forms'] == 'false' && $contact_form->prop('redirection_settings') == 'false'){
return;
}
$redirection_form_id = $contact_form->prop('redirection_settings');
$redirection_page_id = (empty($redirection_form_id)) ? $options['_thank_you_url'] : $redirection_form_id;
$nonce = wp_create_nonce('redirect-user-action');
if($contact_form->prop('redirection_message') != ''){
$args = array(
'html' => false,
'exclude_blank' => false);
$message = wpcf7_mail_replace_tags($contact_form->prop('redirection_message'), $args);
unset($_SESSION['bcf7u_nonce']);
unset($_SESSION['bcf7u_message']);
unset($_SESSION['bcf7u_pageid']);
$_SESSION['_nonce'] = $nonce;
$_SESSION['_pageid'] = $redirection_page_id;
$_SESSION['_message'] = $message;
}
$contact_form->skip_mail = false;
$contact_form->set_properties(
array(
'additional_settings' => "on_sent_ok: \"location.replace('" . get_permalink($redirection_page_id) . "/?nonce=" . $nonce . "');\""));
}
要保存表單字段,只需使用update_post_meta。
還有其他的方法來對wp_ajax_no_priv發送請求基地_ {$動作}動作和js。
告訴我,如果它可以幫助你,或者你需要一些更多的提示!
感謝這個!即將試用它,並會直接返回結果!託姆 –