Skip to content
Advertisement

How to get form data with session in Symfony Form

I’ve been looking for a solution for hours. I’am working with Symfony 3.2.

I’am using Symfony Forms in order to display a data-table (with different filter chosen in the form) with Ajax => No submit button.

I can access to different result of data-table to view more information.

What i want is that when i leave the detail page by clicking on a button and come back on the research page, that i could keep in history all filters that i have chosen.

i wanted use session but actually, it seems has 0 impact. Below is some codes.

Controller:

JavaScript

FormType

JavaScript

I have a problem, there is a EntityType (or Select2EntityType) field named “job” in my form builder and i can’t get the content of this field in my session. This field shows a autocomplete data-list after typing 2 letters, and we can choose one of job.

and also, when i refresh the page, i lose all filters, but i am supposed to store them in session ?

Thanks in advance for your help,

Advertisement

Answer

Yes you can use $form->getData() but to do that you need to do this according to the doc here with using if ($form->isSubmitted() && $form->isValid()) { among others.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement