Checkboxes in symfony 2 form

I have a form defined in the controller as shown below:

$addForm = $this->createFormBuilder() ->add('userIds', 'collection', array( 'type' => 'checkbox', 'allow_add' => true, 'options' => array( 'required' => false ) )) ->add('userId', 'hidden') ->getForm(); 

In the view, I show a datagrid with the option of volume removal. I use paginator for pagination. I manually show the fields in the view as shown below:

 //Inside loop {%for items in pagination %} <input type="checkbox" name="form[userIds][]" class="ids" value="{{items.id}}"/> {%endfor%} 

I get the data in the controller after the mail request, as shown below:

  var_dump($data['userIds']); 

When the user selects three checkboxes, I get the output as shown below:

 array (size=4) 0 => boolean true 1 => boolean true 2 => boolean true 3 => boolean true 

The values ​​should contain userIds, such as 1,5,6,7, but I only get boolean values. What I did wrong?

+4
source share
1 answer

Consider the use of Entity field type : configure using the expanded and multiple properties, you will get a list of flags that will be associated with your model scheme when presented.

+1
source

All Articles