I'm creating a form for users to join a membership site.
http://phippsrealty2.com/test/register2.php
I created the form so that the process page would check to make sure each field had a value, if not send it back to the form page to be filled in. I made it so that it would echo the values already submitted in the text fields. Now I can not get the values of the radio buttons and the drop downs to appear. Otherwise this is very annoying for the user to keep re entering information he has already submitted.
Thanks in advance for any viable solution
Retrieving Drop down/Radio button values
Moderator: General Moderators
-
Duke of PHP
- Forum Newbie
- Posts: 5
- Joined: Mon Apr 21, 2003 2:20 pm
Okay, for the dropdown menu-
Say we had one like this: <select name=grocery><option value=banana>Banana</option><option value=apples>Apples</option>etc.etc.</select>
You see how I had <select name=grocery>? Thats the name of the menu, and how we will work with it. Now, if I wanted to echo whatever the user selected in that dropdown menu, whether it bre apples or bananas, I would do echo "$grocery"; since I named the menu grocery.. And as far as radio buttons go, look at webmonkey.com
Say we had one like this: <select name=grocery><option value=banana>Banana</option><option value=apples>Apples</option>etc.etc.</select>
You see how I had <select name=grocery>? Thats the name of the menu, and how we will work with it. Now, if I wanted to echo whatever the user selected in that dropdown menu, whether it bre apples or bananas, I would do echo "$grocery"; since I named the menu grocery.. And as far as radio buttons go, look at webmonkey.com
Code: Select all
<select name="state">
<option value="">Choose</option>
<option value="AK">AK</option>
<option value="AL">AL</option>
<option value="AR">AR</option>
<option value="AZ">AZ</option>
<option value="CA">CA</option>
<option value="CO">CO</option>Code: Select all
<select name="<?php echo $state; ?>">
<option value="">Choose</option>
<option value="AK">AK</option>
<option value="AL">AL</option>
<option value="AR">AR</option>
<option value="AZ">AZ</option>
<option value="CA">CA</option>
<option value="CO">CO</option>*edit* After reading over your post I'm not positive we are talking about the same thing. I know how to print or echo the value if its submitted. But what I'm trying to accomplish now is when a user fills out a form he forgets a field and is sent back to that page where he forgot a field. Instead of retyping them all, I want all the values to appear so all he has to do is edit the one field he forgot.
- trollll
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 10, 2003 11:56 pm
- Location: Round Rock, TX
- Contact:
I think they meant that on the form page, you would use
...and then in the php that processes the form you would reference the user's state with $state, like this:
That would print out whatever state the user had selected in place of $state. Or you could insert the value of $state into a database, write it to a file, send it to a cookie, etc.
Naming the select with what the user had selected will not work. What I do when I need to have the form "remember" the user's input: set up a loop to cycle through each of the options and if the user has selected one, write it as selected.
This would also work when the user hasn't used the form yet, as $state will not have a value and won't equal any of the states in the array. Hope that helps! 
Code: Select all
<select name="state">
<option value="">Choose</option>
<option value="AK">AK</option>
<option value="AL">AL</option>
<option value="AR">AR</option>
<option value="AZ">AZ</option>
<option value="CA">CA</option>
<option value="CO">CO</option>Code: Select all
echo "Thank you for registering, you live in $state.";Naming the select with what the user had selected will not work. What I do when I need to have the form "remember" the user's input: set up a loop to cycle through each of the options and if the user has selected one, write it as selected.
Code: Select all
$states = Array("AK", "AL", "AR"); // array holding possible values
echo "<select name="state">";
for ($i=0;$i<count($states);$i++) {
// $state got passed from the form
if ($state == $states[$i]) {
print "<option value="" . $states[$i] . "" selected="selected">";
} else {
print "<option value="" . $states[$i] . "">";
}
}
echo "</select>";