Friday, 15 April 2011

Symfony2 form of checkboxes is not updated when nothing is checked -



Symfony2 form of checkboxes is not updated when nothing is checked -

i have user entity , activity. user has many activities. i've created form -> list of users , theris activitis (checkboxes).

user, act1, act2, act3 jhon---x--------0--------0

x- checkbox checked

0- checkbox unchecked

everythings works fine when have info above , press save button, when want uncheck activities:

user, act1, act2, act3 jhon---0--------0--------0

(i press save button) activietes not updated. $_post empty , think there no bindig in controller. single checkbox generated form_widget in way:

input type="checkbox" name="users_activities[users][0][activities][1][enabled]" value="1" checked="checked"

any thought how solve it?

view:

{%for actv in user.activities %} {{ form_widget(actv.enabled) }} {%endfor%}

controller:

$form->bindrequest($this->getrequest()); foreach ($form->get('users') $userf) { foreach ($userf->get('activities') $actf) { $act = $actf->getdata(); $em->persist($act); } } $em->flush();

forms symfony2 checkbox

No comments:

Post a Comment