-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Hi,
it is said at Form Events docs that inside SUBMIT
and POST_SUBMIT
event listeners:
You cannot add or remove fields to the form.
so when I have this code:
->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use ($em) {
$form = $event->getForm();
$repository = $em->getRepository('ZiiwebPurchaseBundle:Tag');
$tag = $repository->find(array('id' => 2));
$form->add('tag', EntityType::class, array('class' => 'ZiiwebPurchaseBundle:Tag'));
$data = $form->getData();
$data->setTag($tag);
$form->setData($data);
I get this error: You cannot change the data of a submitted form.
.
but I can do this without any warning or error:
->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use ($em) {
$form = $event->getForm();
$repository = $em->getRepository('ZiiwebPurchaseBundle:Tag');
$tag = $repository->find(array('id' => 2));
$form->add('tag', EntityType::class, array('class' => 'ZiiwebPurchaseBundle:Tag'));
$form->getData()->setTag($tag); //<<<<<<<<< here I'm chaging the submitted form
Is this a bug or it is kind of allowed to change the submitted data that way?