DR_Waynet
DR_Waynet

Reputation: 1

GravityForms - List Field with multiple DropDown on entries column

I have a list in Gravity forms created with 3 columns, but need the first column to be text, the second to be a drop-down with 3 options and also the third column to be a drop-down with 3 options. I can get the second column to be a drop-down, but fail to get the third.

Using this post: GravityForms - List Field with DropDown on entries column - I can get the following code to work:

add_filter( 'gform_column_input_1_27_2', 'set_column', 10, 5 );
function set_column( $input_info, $field, $column, $value, $form_id ) {
    return array( 'type' => 'select', 'choices' => 'Fluent,Adequate,Basic' );
}

But if I add the code again and set the ID to gform_column_input_1_27_3 to get the following:

add_filter( 'gform_column_input_1_27_2', 'set_column', 10, 5 );
function set_column( $input_info, $field, $column, $value, $form_id ) {
    return array( 'type' => 'select', 'choices' => 'Fluent,Adequate,Basic' );
}

add_filter( 'gform_column_input_1_27_3', 'set_column', 10, 5 );
function set_column( $input_info, $field, $column, $value, $form_id ) {
return array( 'type' => 'select', 'choices' => 'Fluent,Adequate,Basic' );
}

It returns an error:

Cannot redeclare set_column() (previously declared in wp-content/themes/xxxxxx/functions.php:40)

Can someone explain how do I get the third column to display a dropdown like the second does? Thanks.

Upvotes: 0

Views: 1434

Answers (1)

Dave from Gravity Wiz
Dave from Gravity Wiz

Reputation: 2869

You're declaring the set_columns() function twice.

If they will both have the same choices, you could write it like this so that both filters call the same function (without declaring it again):

add_filter( 'gform_column_input_1_27_2', 'set_column', 10, 5 );
add_filter( 'gform_column_input_1_27_3', 'set_column', 10, 5 );
function set_column( $input_info, $field, $column, $value, $form_id ) {
    return array( 'type' => 'select', 'choices' => 'Fluent,Adequate,Basic' );
}

If you need different choices for the second, you can rename the second function:

add_filter( 'gform_column_input_1_27_2', 'set_column', 10, 5 );
function set_column( $input_info, $field, $column, $value, $form_id ) {
    return array( 'type' => 'select', 'choices' => 'Fluent,Adequate,Basic' );
}

add_filter( 'gform_column_input_1_27_3', 'set_column2', 10, 5 );
function set_column2( $input_info, $field, $column, $value, $form_id ) {
return array( 'type' => 'select', 'choices' => 'One,Two,Three' );
}

Upvotes: 1

Related Questions