Getting Selected Dropdown Text/Value

Hi there, I am trying to get the text and value of a dropdownlist in the gform_pre_submission_filter

if i do var_dump none of the items are shown as selected.
//$field = GFFormsModel::get_field( $form, $field_id );
//$choices = $field->choices;

How do i get the text and value that the user has selected?

My end result is to combine several fields together (first name field, lastname field and a select field) and store it in its own field. which is then picked up by dynamics crm plugin to upload to crm.


You can get an idea of everything that was submitted using the gform_pre_submission filter, like this:

add_action( 'gform_pre_submission', 'pre_submission_handler' );
function pre_submission_handler( $form ) {
	var_dump ( $_POST );
	var_dump ( $form );

The $_POST will contain the values what were submitted, and the $form will contain the other information you need about the form.

thanks, i got most of the items i require using rgpost, but when i do the rgpost(‘input_4’) it gives me the value, how do i get the label instead?


Sounds like you are making progress!

To get the field label you will need the field object which is available via the GFAPI: e.g.

$field = GFAPI::get_field( $form, 17 );
$field_label = $field->label;

For choice based fields if you have the choice value and need the choice label you can get that via the field object e.g.

$choice_text = $field->get_value_export( $entry, $field_id, true );

It is the third argument of the fields get_value_export method above being set to true which causes the choice text to be returned.

Hi Chris, thanks for the help,
in the example you show
$choice_text = $field->get_value_export( $entry, $field_id, true );
Where to I get the $entry from as this is done in pre_submission and from what i have read it, presubmission doesnt have the $entry only $form

thanks again

@jamiesw I had the same question. For this example:

I wanted to display the Readable value to show in a summery, not the data value behind it.
$field->choices is an array with with both: text : value

so looping thrue you will get your answer:

$field_data = rgpost('input_' . $field->id);
$field_text = '';
foreach ($field->choices as $choice) {
	if ($choice['value'] == $field_data) {
		$field_text = $choice['text'];
$html_content = $field->label . ': ' . $field_text