expire page on back button symfony2

266 views Asked by At

How do I expire a page once a form is submitted in symfony2?

Sometimes our users are using the back button and re-submit the form. I would like to inform them in case a form has already been submitted that they should not re-submit it.

Sometimes I see on web-pages that the session is expired (when i do online banking for example). when exactly should this be implemented? Would it be appropriate to have it in my situation?

1

There are 1 answers

0
Maltronic On

A simple technique I use to achieve this ad-hoc is a sort of custom csrf session variable.

First add a variable to the session after form submission and then if on page load that variable appears you know they've clicked back.

On the post-submitted page controller add:

$session->set('prevent_back_button', true);

And on the actual form page's controller:

if ($session->has('prevent_back_button'))
{
    $session->remove('prevent_back_button');
    $this->redirect('homepage');
}