doudui6756 2014-02-12 19:48
浏览 45
已采纳

以wordpress形式发送数组数据

I am sending data from a wordpress form in one site to another third party website. When I print_r() the array data on the wordpress form , it displays

Array ( 
[comp_title] => Test incident title 
[comp_desc ] => Officers reported are: first fname officer first lname officer , second fname officer second lname officer , third fname officer third lname officerLocation: locationDescription: desc 
[fullname] => Test reporter fnameTest reporter lname 
[email] => testemail@testreporter.co.ke [phonno] => 0700123456 
[anonymous] => 0 
[fac_id] => 24576 
)

However, on the third party site, when I use var_dump($_GET), it displays array(0).

This is php code from the wordpress site:

add_action("gform_after_submission_1", "set_post_content", 10, 2);
function set_post_content($entry, $form){

//set POST variables
$post_url= 'http://example.com/form_api.php';

$body= array(
'comp_title' =>     urlencode($entry['1']),
'comp_desc' =>     urlencode('Officers reported are: '.$entry['4.3'].' '.$entry['4.6'].' , '.$entry['14.3'].' '.$entry['14.6'].' , '.$entry['13.3'].' '.$entry['13.6'].'. Location: '.$entry['5'].'. Description: '.$entry['6']),
'fullname' =>  urlencode($entry['8.3'].' '.$entry['8.6']),  
'email' =>     urlencode($entry['10']),
'phonno' =>    urlencode($entry['9']),
'anonymous' => urlencode(0),
'fac_id' =>    urlencode(24576)
);

 $fields_string = http_build_query($body);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $post_url);
curl_setopt($ch,CURLOPT_POST, count($body));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

$result = curl_exec($ch);

curl_close($ch);

}      

Then on form_api.php on the third party application i have:

$fac_id =  mysql_real_escape_string($_GET['fac_id']);
$comp_title = mysql_real_escape_string(strtoupper($_GET['comp_title']));
$comp_desc = mysql_real_escape_string($_GET['comp_desc']);
$fullname =mysql_real_escape_string($_GET['fullname']);
$email = mysql_real_escape_string($_GET['email']);
$phonno = mysql_real_escape_string($_GET['phonno']);

What could i be doing wrong?

  • 写回答

1条回答 默认 最新

  • donglin5770 2014-02-12 19:56
    关注

    You're trying to grab GET data, but you are sending the request via POST. Try grabbing $_POST['fac_id'] instead of $_GET['fac_id'].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答