-2

I have a form that takes inputs from user then searches the database and displays the result. Everything is working fine except when the user refreshes the browser there comes an alert about re submission. If I re-submit I get the same data but is there a way to disable that alert? Only refresh and get the same result set.

Here is a screenshot. Re-submission alert Backend - PHP

Abhijit
  • 27
  • 3

4 Answers4

1

There are two ways around this. If your form does not make any modifications to the data or does not log anyone in, you can switch to GET from POST. This has the added advantage of creating urls that can be bookmarked by the user.

If your form submission results in a data modification, you should continue to use POST. However after the data has been modified you should redirect the user to the page where the results are displayed.

Goes something like this

if(isset($_POST['postname'])){ 
    /** modify data here **/
    if ($data_changed) {
       header("Location: /success/page/");
    }
}

This is a recommended practice and a standard pattern in many frameworks. Django immidiately leaps to mind.

e4c5
  • 52,766
  • 11
  • 101
  • 134
0
you can use isset function
if(isset($_POST['postname'])){
// your submission code
}
0

You should use the PRG (Post/Redirect/Get) concept.

The general idea is that when after the POST you Redirect the user to a new page, and this way, even after the refresh - the form is not submitted again.

Dekel
  • 60,707
  • 10
  • 101
  • 129
0

You need to redirect, add this to the end of your script.

header('Location: '.$_SERVER['REQUEST_URI']);

Note this needs to be before any html is output.

Antony Thompson
  • 1,608
  • 1
  • 13
  • 22