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

© 2008 - 2019. Gravity Forms is a project by Rocketgenius Inc.