【问题标题】:How to pass labels and not values with Gravity Forms Checkbox URL Query Parameters如何使用重力形式复选框 URL 查询参数传递标签而不是值
【发布时间】:2018-02-26 12:31:33
【问题描述】:

我需要将标签列表传递到 Wordpress 表单中以创建复选框,最好是重力表单。我知道您可以使用:“允许动态填充字段”,但这只会填充值并且不会动态地制作复选框列表。例如:yahoo.com/?CheckboxLabels=yellow&green&red

复选框:

  1. 黄色
  2. 绿色
  3. 红色

有没有办法做到这一点?谢谢你。

【问题讨论】:

    标签: wordpress checkbox gravityforms


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      通过添加到主题中的functions.php,这最终对我有用。

      <?php
      //NOTE: update the ' 1' to the ID of your form
      add_filter( 'gform_pre_render_1', 'populate_checkbox' );
      add_filter( 'gform_pre_validation_1', 'populate_checkbox' );
      add_filter( 'gform_pre_submission_filter_1', 'populate_checkbox' );
      add_filter( 'gform_admin_pre_render_1', 'populate_checkbox' );
      
      
      
      function populate_checkbox( $form ) {
      
          foreach( $form['fields'] as &$field )  {
      
              //NOTE: replace 3 with your checkbox field id
              $field_id = 6;
              if ( $field->id != $field_id ) {
                  continue;
              }
      
              $input_id = 1;
      
      
              foreach (explode(',', $_GET["addresses"]) as $name => $value) {
      
                  //skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
                  if ( $input_id % 10 == 0 ) {
                      $input_id++;
                  }
      
                  $choices[] = array( 'text' => $value, 'value' => $value );
                  $inputs[] = array( 'label' => $value, 'id' => "{$field_id}.{$input_id}" );
      
                  $input_id++;
              }
      
              $field->choices = $choices;
              $field->inputs = $inputs;
      
          }
      
          return $form;
      }
      
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-10-25
        • 2020-12-08
        • 2016-04-29
        • 1970-01-01
        • 2011-06-03
        • 1970-01-01
        相关资源
        最近更新 更多