如何将表格7的数据联系到谢谢页面

问题描述 投票:0回答:1

我正在使用联系表格7进行调查。当我单击联系表单7提交按钮时,它会重定向到“谢谢”页面。我想获得所有我提交的数据到“谢谢”页面。我该怎么做 ?

wordpress contact-form-7
1个回答
0
投票

有两种方法可以实现,

1。使用一个插件来存储提交的数据,例如Post My CF7 Form(插件页面上有一个FAQ,它说明了如何在重定向的页面上访问存储的提交)。

2。如果您不想存储和保留提交的数据,那么您需要将提交的数据保存到transient并从重定向的页面访问它,可以通过以下方式进行此操作,

[第1步:使用WP nonce作为表单中的隐藏字段,并确定js脚本以重定向到您的页面([使用钩在cf7 successful submission event显示器anonymous function上的do_shortcode_tag触发C0],>

filter

步骤2:一旦提交通过验证/发送电子邮件,钩住cf7操作'wpcf7_mail_sent'。

add_filter('wpcf7_form_hidden_fields','add_hidden_nonce');
function add_hidden_nonce($fields){
  $nonce = wp_create_nonce('cf7-redirect-id');
  $fields['redirect_nonce'] = $nonce;
  /*
   hook the shortcode tag filter using an anonymous function 
   in order to use the same nonce and place a redirect js event 
   script at the end of the form. 
  */
  add_filter('do_shortcode_tag', function($output, $tag, $attrs) use ($nonce){
    //check this is your form, assuming form id = 1, replace it with your id.
    if($tag != "contact-form-7" || $attrs['id']!= 1) return $output;
    $script = '<script>'.PHP_EOL;
    $script .= 'document.addEventListener( "wpcf7mailsent", function( event ){'.PHP_EOL;
    //add your redirect page url with the nonce as an attribute.
    $script .= '    location = "http://example.com/submitted/?cf7="'.$nonce.';'.PHP_EOL;
    $script .= '  }'.PHP_EOL;
    $script .= '</script>'.PHP_EOL;
    return $output.PHP_EOL.$script;
  },10,3);
  return $fields;
}

步骤3:在重定向页面上,您现在可以add_action('wpcf7_mail_sent', 'save_posted_data_into_transient'); function save_posted_data_into_transient(){ if(isset($_POST['redirect_nonce'])){ //save the data. //save the posted data from the form. Note if you have submitted file fields you will also need to store the $_FILES array. set_transient('_cf7_data_'.$_POST['redirect_nonce'], $_POST, 5*60); //5 min expiration. } } 数据,将其放在页面模板的顶部,

access your stored transient
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.