以wordpress形式发送数组数据

时间:2014-02-12 19:48:34

标签: php wordpress gravity-forms-plugin

我将数据从一个网站的wordpress表单发送到另一个第三方网站。 当我在wordpress表单上print_r()数组数据时,它会显示

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 
)

但是,在第三方网站上,当我使用var_dump($ _ GET)时,它会显示数组(0)。

这是来自wordpress网站的php代码:

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);

}      

然后在第三方应用程序的form_api.php上我有:

$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']);

我可能做错了什么?

1 个答案:

答案 0 :(得分:1)

您尝试抓取GET数据,但是您是通过POST发送请求的。尝试抓取$_POST['fac_id']而不是$_GET['fac_id']