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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么