简体   繁体   English

从Gravity Forms表单对象获取单选按钮文本值

[英]Get radio button text value from Gravity Forms form object

I am stripping down the structure of the GF forms object here: 我在这里剥离GF表单对象的结构:

$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. 我想将“ First Choice”放入我的$ label变量中。 I know that this is not correct: 我知道这是不正确的:

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

How would I grab that item? 我将如何抓取该物品?

My solution 我的解决方案

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM