Symfony get data in controller from a form event l

2019-08-09 02:31发布

I'm using Symfony 3.4, I have a FormType and a Listener for this form on preSubmit and postSubmit

In my FormType I run the listener like :

$builder->addEventSubscriber(new MyListener());

My problem is, I need in the postSubmit or preSubmit check a condition for get un boolean, and I need this boolean in my controller after the if ($form->isSubmitted() && $form->isValid()).

My Listener is ok, when I submit the form the listener works well, but I don't knwo how can I get a data from the listener in my controller.

I tried to add a custom non mapped field to the form and set the value in the Listener, but when I try to set the value (true|false) I have an error : "You cannot change value of a submitted form"

I tried something with setData, getData but.. nothing

Any ideas ? Thanks !

1条回答
别忘想泡老子
2楼-- · 2019-08-09 03:23

Finally, I use the session for set my value in the listener, and for get this value in my controller !

Tchao !

查看更多
登录 后发表回答