2

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

复选框:

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

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

4

2 回答 2

0

希望这能解决您的问题。检查链接

https://www.gravityhelp.com/forums/topic/dynamically-populate-checkboxes?replies=2

于 2017-09-18T05:40:50.257 回答
0

通过添加到主题中的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;
}

?>
于 2017-09-18T16:24:11.953 回答