Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing form resubmission

Tags:

http

forms

Page one contains an HTML form. Page two - the code that handles the submitted data.

The form in page one gets submitted. The browser gets redirected to page two. Page two handles the submitted data.

At this point, if page two gets refreshed, a "Confirm Form Resubmission" alert pops up.

Can this be prevented?

like image 940
Emanuil Rusev Avatar asked Oct 13 '10 13:10

Emanuil Rusev


People also ask

What technique is used to help with form resubmission error?

Method #4 Use the PRG Pattern What can pass as a solution to rectifying the Confirm Form Resubmission error is switching the POST method to the entire PRG pattern. Whenever any page needs a form on it, design it in such a way that it does not post the data directly to the server.

How do I turn off confirmation resubmission in Chrome?

Solution 1: Disable Confirm Form Resubmission From ChromeRight click on your chorme shortcut, select properties. In the target field, add: “-disable-prompt-on-repost” without the quotes after chrome.exe.

How do I stop resubmission on Refresh in MVC?

After Form submission, when the Refresh Button in the Browser is clicked or the F5 key is pressed, a warning popup comes up which warns against Form resubmission. The solution is very simple, either the page must be redirected to itself or to some other page in order to avoid this particular behavior.


1 Answers

There are 2 approaches people used to take here:

Method 1: Use AJAX + Redirect

This way you post your form in the background using JQuery or something similar to Page2, while the user still sees page1 displayed. Upon successful posting, you redirect the browser to Page2.

Method 2: Post + Redirect to self

This is a common technique on forums. Form on Page1 posts the data to Page2, Page2 processes the data and does what needs to be done, and then it does a HTTP redirect on itself. This way the last "action" the browser remembers is a simple GET on page2, so the form is not being resubmitted upon F5.

like image 160
CodeTwice Avatar answered Sep 28 '22 05:09

CodeTwice