Dean219 Dean219 - 4 months ago 24
HTML Question

php post dynamic redirect and prevent form resubmit

I am currently having an issue with the back button in my browser and developing a way to hide the resubmit data warning.

After using the POST method to submit data to php I want to redirect to the location /recipe and once there I wish to use the ID submitted from the post method to search the database for the particular ID to display the data :

echo '<div class="text-center"><pre><h4>';
echo '<form action="" method="post"><button type="submit" name="/recipe"';
echo 'value="';echo $id; echo '"class="btn-link">';
print_r($doc[title]);
echo '</button></form></h4><p/><p/>';
echo '<p/></div>';


The Post event handler looks like this :

//PATH for clicking recipe
if(isset($_POST['/recipe'])) {
recipeMethod($log,$user);
} else {

}


So php delivers this form with data from the database->you click the button and it posts the ID of the database element to /recipe so you can view just that element on the next page. This all works as expected...however when you click the back button it reveals a "resubmit the form" warning. Iv looked around stackoverflow however every solution involved using

header("Location: http://example.com/page2.php");


Using this type of redirect just meant the page would redirect to a standard page with no ID being posted and no way for my database to search for the content that i had posted. Does anyone know a way to both submit the ID from my form when the button is clicked, and prevent the resubmit warning from even appearing?

Any help would be appreciated, thanks.

Answer

You can add ID to redirect URL

header("Location: http://example.com/page2.php?ID=123456");