0

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:

    public function indexAction(Request $request)
        {
            $form = $this->createSearchForm();
    
            $request->getSession()->set('form_data', $form->getData());

            $form->handleRequest($request);

            $form->setData($request->getSession()->get('form_data'));
   
            $this->datatable($form->getData());
    
            return $this->render('backend/jobOffer/index.html.twig', [
                'form' => $form->createView()
            ]);
        }

FormType

 public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('publicationState', ChoiceType::class, [
                'label'                     => 'backend.job_offer.publication_state',
                'required'                  => false,
                'choices'                   => JobOffer::getPublicationStateChoices(),
                'choice_translation_domain' => 'choices',
            ])
            ->add('job', Select2EntityType::class, [
                'label'         => 'backend.job',
                'required'      => false,
                'class'         => 'AppBundle:Job',
                'text_property' => 'label',
                'remote_route'  => 'job_autocomplete',
            ])
            ->add('ids', HiddenType::class, [
                'required'                  => false,
            ])
   }

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults([
        'csrf_protection' => false,
        'method'          => 'GET',
    ]);
}

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,

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, i guess that is why i could not use properly $form->getData(), because it's rendering a datatable with call AJAX. So i need to remake my filter system and give up to this ajax system though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.