Skip to content

SUBMIT ad POST_SUBMIT form events: change the data of a submitted form.  #20770

@Ziiweb

Description

@Ziiweb

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy