Welcome to WebmasterWorld Guest from 126.96.36.199
I have an HTML form (index.html), and a script that processes that form called process.php. If the person filling out the form happens to miss one of the first three or four fields, process.php displays some errors and provides a link back to the form- I just want, instead of those fields resetting, I want to keep the information they filled in intact.
I thought if the user typed in their name and missed another field- then came back to the form, the field would be populated:
<input type="text" name="fname" value="<?php $_POST['fname'];?>" size="25" />
Not sure what I'm doing wrong.
Can you include("index.html"); after displaying the errors on your error output page?
Make index.html - index.php and submit the form to itself for processing that way your form variables should still be intact.
If you need to use 2 pages for some reason, on your process.php( in your html output ) you need a hidden form with the variables you want to post back to the first form.
<form action="index.php" method="post">
<input type="hidden" name="fname" value="<?php $_POST['fname'];?>">
<input type="submit" name="submit" value="Return to the previous page with your value intact">
Hope this makes sense :)
By the way, instead of using the link, if you just press the back button, are the values still there?
Try the following with only one file, in that case index.php
First you check if the form was submitted and legit.
for example -> check if the variable exist like : $_POST['submitted'] and the referer is index.php
if that condition is true, do your field validation and if something is wrong, reoutput the form with existing values, but if all fields are ok, output a thank you message or whatever you need (redirect, etc.)
if the condition is false, simply output an empty form.
when you output your form, you can include the following field to check the var submitted
<input type="hidden" name="submitted" value="true" />
hope that helps
[added]Keeper was faster![/added]
That does away with having to change anything in the original form. Better yet, if they keep leaving (other) required data blank, this will continue to work.
process.php will recieve all the values, but that does not mean that index.html will recieve it too, only by clicking a link on the process.php page. the link has to contain the variables in it's query string, like index.html?fname=xxxxx . then index.html will have $_REQUEST['fname'] filled with a value.
you can even turn register_globals [php.net] on and you can use $fname instead.