Title: dynamically fill list?
Last modified: December 2, 2016

---

# dynamically fill list?

 *  [dsjohnson](https://wordpress.org/support/users/dsjohnson/)
 * (@dsjohnson)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/dynamically-fill-list/)
 * How can I dynamically fill the list? I left the options field bland and in my
   plugin I have:
    $list_array = array( array( ‘Column 1’ => rgar($entrie, ‘date_created’),‘
   Column 2’ => “1,2,3”, // column 2 is drop down list ‘Column 3’ => $result, ),
   array( ‘Column 1’ => ‘row2col1’, ‘Column 2’ => ‘row2col2’, ‘Column 3’ => ‘row2col3’),);
   I expected a list of “1”, “2”, “3”, but instead got one entry of “1,2,3” thanks

Viewing 1 replies (of 1 total)

 *  Plugin Author [ovann86](https://wordpress.org/support/users/ovann86/)
 * (@ovann86)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/dynamically-fill-list/#post-8631049)
 * 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 9 years, 5 months ago by [ovann86](https://wordpress.org/support/users/ovann86/).

Viewing 1 replies (of 1 total)

The topic ‘dynamically fill list?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/gravity-forms-list-field-select-drop-
   down_cacfd5.svg)
 * [Drop Down Options in List Fields for Gravity Forms](https://wordpress.org/plugins/gravity-forms-list-field-select-drop-down/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gravity-forms-list-field-select-drop-down/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gravity-forms-list-field-select-drop-down/)
 * [Active Topics](https://wordpress.org/support/plugin/gravity-forms-list-field-select-drop-down/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gravity-forms-list-field-select-drop-down/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gravity-forms-list-field-select-drop-down/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [ovann86](https://wordpress.org/support/users/ovann86/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/dynamically-fill-list/#post-8631049)
 * Status: not resolved