Answer the question
In order to leave comments, you need to log in
How to pass choices values for ChoiceType to Symfony form from controller?
Hello!
I have a ChoiceType in my form. Its values (choices) are entries in the database.
My form is implemented in a separate class:
class FindForm extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
...
->add('type',ChoiceType::class, array(
'choices' => array(
'Значение_1' => '1',
'Значение_2' => '2',
'Значение_3' => '3',
'Значение_4' => '4',
),
'required' => false,
'multiple' => true,
'expanded' => true
))
...
));
}
$form = $this->createForm(FindForm::class);
Answer the question
In order to leave comments, you need to log in
To select entities in forms, there is EntityType:
https://symfony.com/doc/3.4/reference/forms/types/...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question