duanpuchun5275 2018-10-18 09:46
浏览 310
已采纳

无法从Contact Form 7表单发送Wordpress外的POST值

my objective is to submit values via POST of a contact form 7 to a redirected outside php page and echo those values.

The issue is when the page is redirected after the submission, the values seem to be lost unless i remove the JS and change the action Url of the form ending up removing all the contact form 7 features which i require (validation, email sent, etc..).

I tried multiple plugins such as contact form 7 to API and it only works via GET method which i don't want. I tried to get the posted values and transforming them into session but it's not working because i'm probably doing something wrong.

Here's the form: enter image description here

Here's the result that is supose to be shown: enter image description here

UPDATE:

Ok so i posted the function to fetch the posted data and the var_dump missing on the result php file.

Here's the fucntions.php

add_action( 'wpcf7_before_send_mail', 'send_post_values' );


  if ($form_id == 7627) {

    $user      = $cf7->posted_data["user"];
    $email = $cf7->posted_data["email"];
    $country  = $cf7->posted_data["country"];

    //any code missing??

  }

}

Here's the show-values.php

<?php
var_dump($_POST);
print_r($_POST);
echo "Name: " . $_POST["user"] . "<br>"; 
echo "Email: " . $_POST["email"] . "<br>";
echo "Country: " . $_POST["country"] . "<br>";
?>

And here's the JS i put on the edit page of wordpress for redirection

document.addEventListener( 'wpcf7mailsent', function( event ) {
    location = 'https://www.xxxxx.xxx/forms/show-values.php';
}, false );

The output is still missing: enter image description here

Not using any extra plugin besides cf7 at the moment.

  • 写回答

4条回答 默认 最新

  • dongyi1996 2018-10-18 15:12
    关注

    Problem is that when redirecting request on browser side you are basically starting completely new request that will be GET request. Some of the things you can try:

    1. Transfer data as GET parameters. Simplest but not what you want.
    2. Use Javascript to submit form again after first submit but this time to needed URL.
    3. Save data after submit and retrieve it on correct page after redirect. Basically what you tried with session but you said it didn't work. Did you use session_start()? Also it only works if both pages are part of same web page. You can also try storing this data in file/database/somewhere else and maybe passing on some sort of id as GET parameter to find that data after redirect.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办