【问题标题】:Gravity Forms Dynamic Confirmation From FieldsGravity Forms 来自字段的动态确认
【发布时间】:2021-11-25 06:18:52
【问题描述】:

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

我已经接近让它工作了,只是 url 没有正确输出。

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

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

我怀疑这与 Gravity Forms 输出数据的方式有关。这是我的代码:

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;

}

【问题讨论】:

    标签: php gravity-forms-plugin


    【解决方案1】:

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

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

    【讨论】:

    • 我会试一试,告诉你进展如何!感谢您提供替代方法。
    猜你喜欢
    • 2017-04-06
    • 2019-01-04
    • 2015-08-04
    • 2022-01-17
    • 2019-12-28
    • 2018-12-20
    • 1970-01-01
    • 2014-10-20
    • 2019-11-18
    相关资源
    最近更新 更多