I got a form in Symfony but it won't validate and I don't know why.
From UserBundle/Entity/Task.php
/**
*
* @ORM\ManyToMany(targetEntity="Project\TaskBundle\Entity\Task", inversedBy="users")
* @ORM\JoinTable(name="project_users_tasks")
*
*/
protected $tasks;
From UserBundle/Form/CreateUserFormType.php which is my formbuilder:
$builder->add('tasks', 'entity', array(
'class' => 'TaskBundle:Task',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('b')
->andWhere('b.owner = :owner')
->setParameter('owner', $this->securityContext->getToken()->getUser())
->addOrderBy('b.updated', 'ASC');
},
'expanded' => false,
'multiple' => false
));
The post request in my browser:
------WebKitFormBoundary6IBT2Ycy78N9AI7u
Content-Disposition: form-data; name="createUser[tasks][]"
14
The result I get for the form is an error concerning the tasks: "This value is not valid"
I got no other validation what so ever. So why can't the task 14(which is clean the dishes for example) be assigned to my user? I mean the id of the task should work or not?
Edit: Symfony doesn't seem to recognize the data, that's why. A print_r of $form->getData();
[tasks:protected] => Doctrine\Common\Collections\ArrayCollection Object
(
[_elements:Doctrine\Common\Collections\ArrayCollection:private] => Array
(
)
)
But how can that be? I can see that my browser is posting the data.