Reputation: 40758
How can I avoid the the browser form-resubmission alert?
This question seems to have been discussed a lot here on SO, for example:
What I do not get from the previous discussion, is how I can use the posted data and incorporate it into the html. The previous links discuss how to use the php header function to send a get
request to itself. But when sending this get
request, the posted data will no longer be available to the new page, (since we cannot use the php post method..)
I would like to do this without using the php
or javascript
session storage technique (or saving the posted data to a temporary mySQL database).
For a simple example:
<html>
<body>
<form action="post.php" method="post">
User name: <input type="text" name="user"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
where post.php
is:
<html>
<body>
<?php
echo "<p>".$_POST['user']."</p>";
?>
</body>
</html>
Pressing CTRL-R in google chrome on the second page brings up the alert.
Upvotes: 2
Views: 2543
Reputation: 95
Use this:
<script>
if(window.history.replaceState)
{
window.history.replaceState(null,null,window.location.href);
}
</script>
Upvotes: 1
Reputation: 25143
you may rewrite the browser history
object
history.replaceState("", "", "/the/result/page");
See this
Upvotes: 0
Reputation: 21449
Do a redirect from post.php
. Save data in session or in database and retrieve from redirect page.
Example Scenario:
$id
header('Location: result.php?user_id='.$id);
Upvotes: 3