Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop browsers asking to resend form data on refresh

Tags:

html

post

firefox

I have a form submission via POST. I submit the form, and all is well, however if I try to reload the new page that the form goes to after submission, I get the "Do you want to resend data" message (Firefox). It might happen in other browsers too, but I'm not sure.

Is there a way to stop this message popping up so I can go ahead and refresh the page? It's not good for production environments - users may submit the same form twice!

like image 743
Bojangles Avatar asked Dec 01 '10 17:12

Bojangles


People also ask

How do I stop confirmation resubmission on refresh?

You can prevent form resubmission via a session variable. Yes we can use microtime() as well as time() also instead of rand() , whatever function or variable that gives different value we can use it. BUT make sure that you set that value to SESSION variable.

How do I stop form submit on page refresh?

Use the preventDefault() method on the event object to prevent a page refresh on form submit in React, e.g. event. preventDefault() . The preventDefault method prevents the browser from issuing the default action which in the case of a form submission is to refresh the page.

How do I stop a form resubmission when a page is refreshed in asp net?

As you probably know, ASP.NET Web Forms send POST requests back to the server and then re-render the Page in the same request. This is why we see the form re-submission message when we click "reload". To avoid this issue, we should employ the post-then-redirect pattern used by many web applications.


2 Answers

You need to use the the POST-Redirect-GET pattern.

Make your form respond with a redirect to a GET request.
This way, when the user refreshes the page, it will only resend the GET.

like image 163
SLaks Avatar answered Oct 07 '22 05:10

SLaks


An easy way after response.sendRedirect is to reload the page in this way:

window.location.href = window.location.pathname; 

It works for me.

like image 28
Merboy Avatar answered Oct 07 '22 04:10

Merboy