以公式验证选择类型

I have this kind of ChoiceType Field

                'Answers',
                ChoiceType::class,
                [
                    'choices' => [
                        'foo' => true,
                        'fooBar' => false,
                        'fooB' => false,
                    ],
                    'expanded' => true
                ]
            )



How can i validate this in my controller ?

After i choose foo for example. Here

if ($form->isSubmitted() && $form->isValid()) {

        }

You can access your choices variable like so :

If you use Request request in the parameter of your function you can use

$choices = $request->get('yourFormName')['choices'];

Or in your case, using your $form variable

$choix = $form->get('choices')->getData();

So use this to check if the result is what you want or not.