Hans Schwimmer
Hans Schwimmer

Reputation: 139

How to access choice from form in Symfony

I have following form builder:

$builder->add('status', 'choice', array('attr' => array(
            'choices' => array('0' => 'Principal', '1' => 'Teacher', '2' => 'Student'),
            'required' => true, 'expanded' => 'false', 'multiple' => 'true'
          )));

How to present those 3 values as radio buttons in twig template in a way like below presented(it doesn't work)?

{{ form_start(form) }}
{{ form_widget(form.status.choices[0]) }}
{{ form_end(form) }}

Upvotes: 0

Views: 141

Answers (1)

Max Lipsky
Max Lipsky

Reputation: 1852

If you want radio buttons you need change options to 'expanded' => 'true', 'multiple' => 'false'

enter image description here

In twig:

{{ form_start(form) }}
{{ form_widget(form.status) }}
{{ form_end(form) }}

More information: choice Field Type

Upvotes: 2

Related Questions