I made a search form in order to let user choose the city and category (for events). When I land on events.html.twig, I get to right informations. :)
Now, what I'm trying to do is when I go back to the search form, I'd like to keep the values I set last time in the form. I want retrieve them when I go back to the search form so that when I want to change only one thing, I can. ^^
I tried some solution (it's in the comments) by opening a session in order to keep the values entered in the form. At the moment, I am lost in my code. I don't know how I can do it.
<?php
namespace App\Controller;
use App\Form\SearchType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class EventsController extends AbstractController
{
#[Route('/search', name: 'search')]
public function search(Request $request)
{
/* $session = $this->requestStack->getCurrentRequest()->getSession(); */
/* $session->set($data); */
$form = $this->createForm(SearchType::class/* , $data */);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
/* $session->set($data); */
return $this->render('front/events.html.twig', $data);
}
return $this->render('front/search.html.twig', [
'form' => $form->createView(/* $data */)
]);
}
}