Solved

Form doesn't refresh entered values when using back button

Posted on 2004-10-15
11
341 Views
Last Modified: 2006-11-17
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
Comment
Question by:earthman100
  • 5
  • 4
  • 2
11 Comments
 
LVL 11

Expert Comment

by:neester
Comment Utility
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
 
LVL 11

Expert Comment

by:neester
Comment Utility
this way - they wont need to hit backj
0
 

Author Comment

by:earthman100
Comment Utility
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
 
LVL 11

Expert Comment

by:neester
Comment Utility
Its a browser issue.
I dont think there is anything you can do.
Perhaps change the form from POST to GET...
0
 

Author Comment

by:earthman100
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:earthman100
Comment Utility
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
 
LVL 11

Expert Comment

by:neester
Comment Utility
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
 
LVL 12

Accepted Solution

by:
minichicken earned 500 total points
Comment Utility
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
 
LVL 11

Expert Comment

by:neester
Comment Utility
Seeing as I dont use IE.
Thats probably your answer there :)
0
 

Author Comment

by:earthman100
Comment Utility
perrrfect.  Thanks minichicken!
0
 
LVL 12

Expert Comment

by:minichicken
Comment Utility
Great Stuff.... No prob.. :)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now