Search code examples
phpgravity-forms-plugin

Get radio button text value from Gravity Forms form object


I am stripping down the structure of the GF forms object here:

$form =
array(22) 
    { 
    ["fields"]=> array(2) 
        { 
        [1]=> object(GF_Field_Radio)#1732 (40) 
            { 
            ["choices"]=> array(2) 
                { 
                [0]=> array(4) 
                    { 
                        ["text"]=> string(12) "First Choice"
                    } 
                [1]=> array(4) 
                    {
                        ["text"]=> string(13) "Second Choice" 
                    } 
                } 
            } 
        }
    }

I would like to put 'First Choice' into my $label variable. I know that this is not correct:

$label = $form['fields'][1]['choices'][0]['text'];

How would I grab that item?


Solution

  • My solution

        $field_id = 4;
        $field = GFFormsModel::get_field( $form, $field_id );
        $choice_text = $field['choices'][$entry[$field_id]]['text'];
        $data = $choice_text;