Hey,
Sorry for the delay – I didn’t get a notification.
You’ll need to modify the form object using the gform_pre_render filter (and the other similar filters).
Example below shows how to do this — for FORM ID 1 FIELD ID 20 and COLUMN LABEL ‘Column 1’. Note how the values are a comma separated string (and we can’t define the option value separately at the moment).
(note I’ve assumed you’re working with a multi-column list field)
add_filter( 'gform_pre_render', 'my_gform_pre_render', 10, 1 );
add_filter( 'gform_pre_validation', 'my_gform_pre_render', 10, 1 );
add_filter( 'gform_admin_pre_render', 'my_gform_pre_render', 10, 1 );
add_filter( 'gform_pre_submission_filter', 'my_gform_pre_render', 10, 1 );
function my_gform_pre_render( $form ) {
if ( GFCommon::is_form_editor() || 1 != $form['id'] ) {
return $form;
}
if ( is_array( $form ) || is_object( $form ) ) {
foreach ( $form['fields'] as &$field ) { // for all form fields
$field_id = $field['id'];
if ( 20 != $field_id ) {
break;
}
if ( 'list' == $field->get_input_type() ) {
$has_columns = is_array( $field->choices );
if ( $has_columns ) {
foreach ( $field->choices as $key => &$choice ) { // for each column
$isDropDown = rgar( $choice, 'isDropDown' );
$column = rgars( $field->choices, "{$key}/text" );
if ( $isDropDown && 'Column 1' == $column ) {
$choices = 'Option 1, Option 2, Option 3';
$choice['isDropDownChoices'] = $choices;
}
}
}
}
}
}
return $form;
}
-
This reply was modified 7 years, 10 months ago by ovann86.