[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-13
4
Medium Priority
?
401 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:Andrew Angell
  • 2
4 Comments
 
LVL 82

Expert Comment

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

Open in new window

0
 
LVL 7

Expert Comment

by:aherps
ID: 22956441
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
 
LVL 15

Expert Comment

by:quincydude
ID: 22956493
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
 
LVL 15

Accepted Solution

by:
quincydude earned 2000 total points
ID: 22956509
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month19 days, 17 hours left to enroll

872 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