引力从场形成动态确认



我在多个页面上有一个表单,我需要自定义确认重定向来跟踪Google转换。

除了url不能正确输出外,我已经接近让它工作了。

我希望它是:https://example.com/location/city-name/product-name/

然而,当我提交表单时,我得到这个:https://example.com/location/$location/$product,所以它显然不会进入正确的页面。

我怀疑这与重力表单输出数据的方式有关。下面是我的代码:

add_filter( 'gform_confirmation_8', 'dynamic_confirmation', 10, 4 );
function dynamic_confirmation($confirmation, $form, $entry, $ajax) {
$product = rgar( $entry, 'location_product');
$location = strtolower(rgar( $entry, 'location_title'));
$location = str_replace(',', '', $location);
$location = str_replace(' ', '-', $location);
$url = 'https://example.com/location/'.$location.'/'.$product;
$confirmation = array( 'redirect' => $url );
return $confirmation;
}

您可以在提交后尝试以下操作,而不是使用确认过滤器:

add_action( 'gform_after_submission_8', 'dynamic_confirmation', 10, 2 );
function dynamic_confirmation($entry, $form ){ 
$product =$entry['2'];//replace 2 with field number with product name
$location = strtolower($entry['3']);//replace 3 with field number with location title
$location = str_replace(',', '', $location);
$location = str_replace(' ', '-', $location);
header('Location: https://example.com/location/'.$location.'/'.$product);
exit();
}

最新更新