spivurno
6/30/2014 - 6:25 PM

Get the selected survey choice based on entry value.

Get the selected survey choice based on entry value.

/**
 * Get the selected survey choice based on entry value. 
 */
function gw_survey_get_selected_choice( $entry, $field_id ) {

    $form = GFAPI::get_form( $entry['form_id'] );
    $key = rgar( $entry, $field_id );

    foreach( $form['fields'] as $field ) {

        if( $field['id'] != $field_id )
            continue;

        foreach( $field['choices'] as $choice ) {
            if( $choice['value'] == $key )
                return $choice;
        }

    }

    return false;
}