Search code examples
symfonycheckboxentity

symfony2 FromBuilder multiple checkboxes from entity instead of using "choice"


How can I get multiple Cehckboxes instead a choice field in Symfony? Actually, I'm using:

->add('usergroups', 'entity', array('class' => 'PrUserBundle:Group','property' => 'name','required' => true))

This will output a select-Field..

In this case, it would be better to output checkboxes as it is easier to handle for the user.

http://symfony.com/doc/current/reference/forms/types/checkbox.html at, there is nothing helpful about multiple select.... Do I have to build an array and place it by myself?


Solution

  • Use the expanded option for choice and entity fields.

    ->add('usergroups', 'entity', array('class' => 'PrUserBundle:Group','property' => 'name','required' => true, 'expanded' => true,))