Populate field based on the label from another field [RESOLVED]

I read the documentation on how to populate a field using the value from another field.

// Change 1 on the following to your form id number.
add_action( 'gform_pre_submission_1', 'pre_submission_handler' );
function pre_submission_handler( $form ) {
    // Change 14 and 5 to the id number of your fields.
    $_POST['input_14'] = rgpost( 'input_5' );
}

In my case, ID:14 is a text-field and ID:5 is a dropdown.

Is it possible to pass the textlabel (not the value) of the dropdown selected choice? What should be in place of rgpost(‘input_5’ )?

Choice labels are not POSTed, you would need to get $field from the $form and extract the choice label from it.

I would really like to give it a try. Can you give me a code example as a start?

The following will work, you only need to change the form id and field id’s:

// Change 3631 on the following to your form id number.
add_action( 'gform_pre_submission_3631', 'gf_override_field_with_choice_label' );
function gf_override_field_with_choice_label( $form ) {

	// Get field id 1.
	$field = GFAPI::get_field( $form, 1 );
	
	// Get field value.
	$choice_value = rgpost( 'input_1' );
	
	// Get field label.
	$choice_label = GFFormsModel::get_choice_text( $field, $choice_value );

	// Change 3 to the id number of the field to store the choice label.
	$_POST['input_3'] = $choice_label;
}

Thanks a lot, this helped me on the right track.