• 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

    (@ovann86)

    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.
Viewing 1 replies (of 1 total)
  • The topic ‘dynamically fill list?’ is closed to new replies.