重力形式(WP):来自after_submission的全局变量

时间:2016-09-07 15:59:56

标签: wordpress gravity-forms-plugin

一旦用户提交表单,我试图抓取字段1中的数据,将其分配给变量,然后在另一个函数中尝试使用该数据。

数据成功进入after_submission函数中定义的变量,因为我能够简单地告诉站点如果变量中有某个单词就会中断。现在需要从不同的函数获取相同的数据。

add_action("gform_after_submission", "after_submission", 10, 1);
function after_submission($entry, $form){

$shopname = $entry["1"];
global $response;
$response = 'https://openapi.etsy.com/v2/shops/'. $shopname .'/listings/active?api_key=xxxxxxxxxxxxx )';
}

function dynamic_url(){
$apiurl = $response;
return $apiurl;
}

1 个答案:

答案 0 :(得分:0)

在第二个函数中重新声明全局变量:

add_action("gform_after_submission", "after_submission", 10, 1);
function after_submission($entry, $form){

$shopname = $entry["1"];
global $response;
$response = 'https://openapi.etsy.com/v2/shops/'. $shopname .'/listings/active?api_key=xxxxxxxxxxxxx )';
}

function dynamic_url(){
global $response;
$apiurl = $response;
return $apiurl;
}