How to keep forms filled in when going back...???

I've got a checkout form where the user fills in their billing and shipping information.  When they submit shipping gets calculated and payment processing occurs.  If there is an error during either of these 2 stages it's displayed on screen and then when you go back to the form it's empty again.

I was able to fix most of the form fields because I keep everything in session variables so I set the initial value of text fields to check if the session exists and then use it for the initial value if it does.  This pre-populates most of the fields for me which is nice, but it's not that easy with big drop down menus where you just have to put selected="selected" on the option to make it the default.  

So as it stands now all of my text fields get pre-populated but I haven't taken the time to fix all of the drop downs.  they go back to default when you get back to this page and you have to set them again.  

Is there any way to get around this problem or just get the browser to keep the fields even after posting the form and coming back?
LVL 11
Andrew AngellCo-Owner / DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
if you currently have:
<input name="fieldname" value="" /> 
change it to:
<input name="fieldname" value="<?=$_REQUEST['fieldname']?>" />

Open in new window

0
aherpsCommented:
You can set the selected items within session variables when you post, and if the page is revisited, you can add the somehting like:

<Option value="option_name" <% IF ($_SESSION["variable_name"] == "this_option") echo "SELECTED" ?> VariableName

0
quincydudeCommented:
Hi, it's not very hard for setting drop downs, check this sample, I put the menu options in a DB and query them at runtime. Hope this helps.
			$taglist = mysql_query($sqltags);
			
			echo "<select name=\"tag\" \">";
 
			if($taglist && mysql_num_rows($taglist) > 0)
			{
				while($atag = mysql_fetch_array($taglist))
				{
					echo "	<option value =\"" . $atag['ctag'] . "\" ";
						if($atag['ctag'] == $_SESSION['TAGNAME'])
							echo "selected=\"selected\" ";				
					echo ">" . $atag['ctag'] . "</option>";
				}
			}
 
			echo "</select>";

Open in new window

0
quincydudeCommented:
fixed some typos
			$taglist = mysql_query($sqltags);
			
			echo "<select name=\"tag\" >";
 
			if($taglist && mysql_num_rows($taglist) > 0)
			{
				while($atag = mysql_fetch_array($taglist))
				{
					echo "	<option value =\"" . $atag['ctag'] . "\" ";
						if($atag['ctag'] == $_SESSION['TAGNAME'])
							echo "selected=\"selected\" ";				
					echo ">" . $atag['ctag'] . "</option>";
				}
			}
 
			echo "</select>";

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.