Solarpitch Posted June 1, 2007 Share Posted June 1, 2007 Hey Guys, You know when you submit a form on the same page and you display a list of errors back to the user . . please fill username etc. You then use value="<?print $firstname; ?>" and so on to fill in the fields that the user has already entered correctly so they dont have to fill that part in again. Just want to know how you do it for list boxes because when you use value="<?print $category; ?>" for a listbox it doesnt seem to work. Quote Link to comment https://forums.phpfreaks.com/topic/53853-using-value-on-forms/ Share on other sites More sharing options...
per1os Posted June 1, 2007 Share Posted June 1, 2007 <select name="listbox" size=20> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> It is because a list box is setup differently. You would have to format the $category and have each option laid out like above. Quote Link to comment https://forums.phpfreaks.com/topic/53853-using-value-on-forms/#findComment-266299 Share on other sites More sharing options...
TreeNode Posted June 1, 2007 Share Posted June 1, 2007 Here's how I do it: <select name="state"> <?php $user_state = $_POST['state']; $state_list = array( "AL" => "Alabama ", "AK" => "Alaska ", "AZ" => "Arizona ", "AR" => "Arkansas ", "CA" => "California ", "CO" => "Colorado ", ... ); foreach ($state_list as $key => $value) { $selected = ""; if ($key == $user_state) $selected = 'selected="selected"'; // Loop HTML ?> <option <?=$selected?>value="<?=$key?>"><?=$value?> </option> <?php // End HTML } ?> </select> Keep in mind that I have short-tags enabled. Quote Link to comment https://forums.phpfreaks.com/topic/53853-using-value-on-forms/#findComment-266310 Share on other sites More sharing options...
Solarpitch Posted June 1, 2007 Author Share Posted June 1, 2007 Hey thanks guys, I figured out another way to do it... So if you submitted a form check this by setting process == 1 and fill the options based on it.. <? if ($_POST['process'] == 1) { print $county; } else { print "Please Select..."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53853-using-value-on-forms/#findComment-266316 Share on other sites More sharing options...
Solarpitch Posted June 1, 2007 Author Share Posted June 1, 2007 The above seems to do the job . . but while I am on the subject, how would you approach it for radio buttons? Quote Link to comment https://forums.phpfreaks.com/topic/53853-using-value-on-forms/#findComment-266317 Share on other sites More sharing options...
Solarpitch Posted June 1, 2007 Author Share Posted June 1, 2007 Hey . . doesnt matter . . I figured it out using <input type="radio" name="contact_preference" value="Email" <? if ($_POST['process'] == 4) { if ($contact_preference == "Email") print "checked"; } ?>> Email Quote Link to comment https://forums.phpfreaks.com/topic/53853-using-value-on-forms/#findComment-266320 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.