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?
 
quincydudeConnect With a Mentor Commented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.