Dynamically Populated Dropdown not saved in entry [RESOLVED]

I have a problem where the data for the dropdown selection is not saved with the entry. I added a field that is not pre-filled and that value does get saved. Pre-fills for checkboxes, text and numbers all work fine. What am I missing for dropdowns?

I pre-populate a form with the hooks:

add_filter( 'gform_pre_render_2', 'populate_store_update' );
add_filter( 'gform_pre_validation_2', 'populate_store_update' );
add_filter( 'gform_pre_submission_filter_2', 'populate_store_update' );
add_filter( 'gform_admin_pre_render_2', 'populate_store_update' );

The code snippet for one of the dropdown fields is (I adapted this code from this forum):

 if ($field->inputName == 'storeownership'){
                $field_id = $field->id;
                $input_id = 1;
                $currentsownership =$respArray['Value'];  // this is the currently selected choice
                foreach( $ownerships as $ownership ) {
                    //skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
                    if ( $input_id % 10 == 0 ) {
                        $input_id++;
                    }
					if ($ownership == $currentsownership){
						$ownerChoices[] = array( 'text' => $ownership, 'value' => $ownership, 'isSelected' => 1 );
					} else {
						$ownerChoices[] = array( 'text' => $ownership, 'value' => $ownership);
					}
                    $ownerInputs[] = array( 'label' => $ownership, 'id' => "{$field_id}.{$input_id}" );
                    $input_id++;
                }
                $field->choices = $ownerChoices;
                $field->inputs = $ownerInputs;    
            } //end of storeownership

I looked at the page code for the form preview and at the form as pre-filled. I don’t see any significant issues:
Form field in preview:

< li id='field_2_44' class='gfield field_sublabel_below field_description_below gfield_visibility_visible' >
< label class='gfield_label' for='input_2_44' >Location< /label><
      < select name='input_44' id='input_2_44' class='medium gfield_select' aria-invalid="false">
            < option value='First Choice' >First Choice</option>
            < option value='Second Choice' >Second Choice</option>
            < option value='Third Choice' >Third Choice</option>
      < /select>
< /div>< /li>

Form files as pre-filled:

    < li id='field_2_44' class='gfield field_sublabel_below field_description_below gfield_visibility_visible' >
    < label class='gfield_label' for='input_2_44_1' >Location</label>
    < div class='ginput_container ginput_container_select'>
          < select name='input_44' id='input_2_44' class='medium gfield_select' aria-invalid="false">
                < option value='Branch' >Branch</option>
                < option value='Main' selected='selected'>Main</option>
          < /select>
    < /div>< /li>

I got the answer through GF support.

$field->inputs = $ownerInputs;
should become:
$field->inputs = null;

I just wanted to document the resolution.

1 Like

Thank you for posting that. As @richardw8k said:

Dropdown fields don’t use inputs so if the inputs property is populated that would cause an issue when the entry is saved.