php - How to prevent "confirm form resubmission" popup after failed form submission
When form submission fails, same webform is presented to user with the error messages which is fine however, when they hit F5 or use back/forward buttons of browser, "Confirm re-submission" popup appears. How can prevent this action?
Note: I used to use redirection method in CodeIgniter without losing error messages but I don't know how to handle same kind of process in Symfony since I'm new to it. Any solution is acceptable though.
Controller:
namespace Se\HirBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Se\HirBundle\Entity\Task;
use Se\HirBundle\Form\Type\TaskType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class TodoController extends Controller
{
public function indexAction()
{
$task = new Task();
$form = $this->createForm(new TaskType(), $task, array('action' => $this->generateUrl('todo_new')));
return $this->render('SeHirBundle:Default:todo.html.twig',
array('page' => 'Todo', 'form' => $form->createView()));
}
public function newAction(Request $request)
{
if ($request->getMethod() == 'POST')
{
$task = new Task();
$form = $this->createForm(new TaskType(), $task, array('action' => $this->generateUrl('todo_new')));
$form->handleRequest($request);
if ($form->isValid())
{
$task = $form->get('task')->getData();
$due = $form->get('due')->getData();
$data = $form->getData();
echo '<pre>'; print_r($data);
return new Response("Well done: $task - $due");
}
else
{
return $this->render('SeHirBundle:Default:todo.html.twig',
array('page' => 'Todo', 'form' => $form->createView()));
}
}
else
{
return new Response('Only POST method accepted');
}
}
}
Answer
Solution:
Error bubbling true is what groups all of the errors together. Set this false.
The error popup is based on your browser. I'm not sure that can be shut off via Symfony. The
should have done this already.
Answer
Solution:
Trick is to keep form data in a session and populate form type with the data stored in same session for failing forms submissions. Data stays in session until successful form submission.
Full example is here: Preventing 'Confirm form resubmission' dialog in symfony applications