• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

Form doesn't refresh entered values when using back button

Hi, I have an HTML form that a user fills in, and then it is submitted to a confirmation page.  Only problem is, if they click the back button to change something, the form is not showing their entered values.  I thought this was standard behaviour for browsers to do so.  Could anyone offer some ideas as to why it is not working, please?

Thanks!
0
earthman100
Asked:
earthman100
  • 5
  • 4
  • 2
1 Solution
 
neesterCommented:
Are you using PHP to control the form.

What you can do is.
have the forms like this:

<input type="text" name="username" id="username" value="<?=$_POST['username']?>" />

Then when they submit the form it will submit the values to itself.

So have something like this

<?

// form validation code here!!!

// if validated fine - then redirect (use this:
header('location: newpage.php');
exit;
// if not, show error message...
echo("your form didnt validate!");
?>
<form action="thispage.php" method="post">
<input type="text" name="username" id="username" value="<?=$_POST['username']?>" />
<input type="text" name="username" id="username" value="<?=$_POST['username']?>" />
<input type="text" name="username" id="username" value="<?=$_POST['username']?>" />
<input type="text" name="username" id="username" value="<?=$_POST['username']?>" />
</form>


Does that make sense??



its obviousl really cut up and short.
but if you are using PHP it will probably make sense to you!
0
 
neesterCommented:
this way - they wont need to hit backj
0
 
earthman100Author Commented:
I have used that before, but I do not want to do that.  I am sending the form to another page that confirms the info they entered in a text version.  I just want the back button to work the way it should, and cannot figure out why it won't.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
neesterCommented:
Its a browser issue.
I dont think there is anything you can do.
Perhaps change the form from POST to GET...
0
 
earthman100Author Commented:
Well, it's unfortunate to see you dismiss things so easily.

It is not a browser issue.  Through debugging it I believe I have discovered that it has something to do with the javascript that I am using on the page, not with the form itself.  

That is simply the answer I was looking for, as I know that the browser's back button works fine with forms as it's meant to...that hasn't changed.

Thanks anyways.
0
 
earthman100Author Commented:
AHA...it was the PHP command:

session_start();

that caused it not to reload the values.  Wish I knew why, if anyone can tell me I will award them the points.

Anyways, mystery solved.
0
 
neesterCommented:
EarthMan.
Sorry - Logically it seems that it wouldnt be anything Server Side - that is why I said it would be browser based.
If you hit back, it shouldnt actually reload any content.
It should just load the cache...

odd...
sorry.
0
 
minichickenCommented:
Hi

Are you using IE??
Take a look at http://www.phpfreaks.com/tutorials/41/1.php about Microsoft Internet Explorer Sessions Fix.

If you are using session_start(); then you also need to use header("Cache-control: private"); below it, to avoid the IE bug

So you have this if you use sessions on that page

session_start();
header("Cache-control: private"); //IE fix

regards
0
 
neesterCommented:
Seeing as I dont use IE.
Thats probably your answer there :)
0
 
earthman100Author Commented:
perrrfect.  Thanks minichicken!
0
 
minichickenCommented:
Great Stuff.... No prob.. :)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now