Symfony2 form submitting on page refresh

Ronald picture Ronald · Apr 26, 2013 · Viewed 8.5k times · Source

I have a form in Symfony2 framework. On successful submission of the page it renders another twig template file and returns the values by passing the parameters in an array. But after submission, if I refresh the page, again it is submitting the form and the table entry is created. Here is the code that is executed after submission in the controller,

$this->get('session')->setFlash('info', $this->get('translator')->trans('flash.marca'));

return $this->render('NewBundle:Backend:marca.html.twig', array(
                                        'active' => 1,
                                        'marca' => $marca,
                                        'data' => $dataCamp,
                                        'dataMarca' => $this->getMarcas($admin->getId()),
                                        'admin' => $admin,
            ));

I want the form to be redirected to the twig files mentioned there with the parameters and the alert message mentioned above. But I don't want the form to be submitted on page refresh.

Thanks

Answer

Francesco Borzi picture Francesco Borzi · Apr 15, 2016

This worked for me:

return $this->redirectToRoute("route_name");