Step 1- Fill form and press save.
Step 2- Get a alert message. press ok
Step 3- Now Press F5 (Refresh).
Problem- Every time when i press F5 for refresh i am getting the old alert message even i fill the form press save button.
Can anyone tell me why this happening or is there any solution to get out of this?
Thanks
So you:
1- Post the form
2- Get the message
3- Refresh the page and still get the message
If that’s the case, it’s because the browser will resend the data when you press F5 on a page that was displayed by a “POST”. The browser will refresh the page depending on how you accessed it (via a GET - like a normal like, or a POST - like with a form). But I think that the browser should ask you if you want to “repost” the data. Is the browser asking anything?
You could also debug with the “network” tab in Chrome developer tools and see if your browser is asking the page or if the page is coming from a cache somewhere.
if i do CTRL +F5 in Firefox it show the message
Confirm dialogue box,
"To Display this page, Firefox must send information that will repeat any action ( such as a search or order confirmation ) that was performed earlier.
Is there any way to prevent this to happen?
If i only press F5 in Firefox it don’t give any message,
but i do CTRL + F5 in Firefox it show the message
Confirm dialogue box,
"To Display this page, Firefox must send information that will repeat any action ( such as a search or order confirmation ) that was performed earlier.
And In case of chrome it give message that is.
“Confirmation message.
The page that you’re looking for used information that you entered.
Returning to that page might cause any action that you took to be repeated.
Do you want to continue?”
hi John_Betong ,
Thanks for your code but the thing is that i don’t want to refresh the page. i just want to show my message and restart from the beginning.
As in my current case it start from the beginning but if i refresh the page it show the same message with the same old data.
I don’t want this to happen because in will cause a problem if the user do this?
What i want that if once submit it show message and done, and don’t show message until next submit of data.
Thanks
Try the script I supplied, reduce the time to refresh to one second and you will notice a message appearing at the page bottom once and once only before the page is refreshed.
When the page is refreshed all post variables are cleared.
If any other member has a solution I would be grateful for the script.
In websites and applications I worked on, when there is a post, we just do a redirect after the post is done and then display a message on the page, not with a JavaScript popup. If the user refreshes the page, the form won’t be reposted. But, the message will be displayed again, but honestly, that’s not really a problem since it’s not a JavaScript dialog box. This, or you just post the form in Ajax, that way, you won’t have this problem.
But by this way i will not able to get the value of php variable because it will not be there after post by jquery or ajax done.
i only can show message but i too want a variable with value must be shown.
Thanks
If JavaScript was the only way to display PHP variables, there would be JavaScript popups everywhere. And well, there’s not a lot of them
Here’s an example on how you could just display the message directly into the page, without a JavaScript popup:
<?php
$msg = "";
if(isset($_POST['save']))
{
$name=$_POST['name'];
$id=$_POST['id'];
$msg = "check message: $name :- $id";
}
else
{
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php if (!empty($msg)): ?>
<div class="title"><?= $msg ?></div>
<?php endif; ?>
... your html form here ...
</body>
</html>
That way you won’t have to use those ugly (and annoying) JavaScript dialog boxes
You see the block <?php if (!empty($msg)): ?>? It will enter in this IF if the variable $msg isn’t empty.
We close that block with the “endif”.
And we display the MSG variable with <?= $msg ?>. This is the equivalent of <?php echo($msg); ?>
Some free tip: I know that you’re only trying stuff out, but when you’re ready to create a script to put live on the Internet, consider using HTML5. Also, using <table> to display design is a bad practice, we used to that in the end of the 90s (seriously). You should check out tutorials about CSS3 and HTML5. If you took that code from a tutorial or a book, I would find another source, because it seems outdated