Redirecting after Processing a POST Request

Learn how to redirect the user after processing a POST request.

Confirmation required after refreshing the page

Let’s go back to where we were. The /name.php page asks the user to enter their name. After submitting the form, we save their name in a cookie so we can use it in the next request.

One usability issue we have is that after submitting the form, the user is still looking at a page that is the result of the POST request. This means that if they refresh the page, it’s going to resubmit the form data. Not bad per se, but it is not ideal that a confirmation dialog pops up, asking if the user wants to send the data to the server again. The user should not have to worry or make a decision about this.

Run the below code, and go to the link given below the Run button to view the webpage in a separate tab. Fill the form, submit it, and refresh the page by clicking the refresh button. You will see a dialog popping up that asks for confirmation.

Get hands-on with 1200+ tech skills courses.