louis_coetzee Posted January 13, 2009 Share Posted January 13, 2009 It's common courtesy to ensure that a form with validation problems reposts with the fields still filled in, so the user doesn't have to start over, by echoing the variables in the Value attribute of the text fields, but I also want to have a drop-down menu to be sticky and retain its selected state when the page reposts. Quote Link to comment Share on other sites More sharing options...
waterssaz Posted January 13, 2009 Share Posted January 13, 2009 How are you creating your drop down box? Static or dynamic? Quote Link to comment Share on other sites More sharing options...
louis_coetzee Posted January 13, 2009 Author Share Posted January 13, 2009 It's basically a static dropdown on a registration page, it then posts, validates, if errors are detected, i need the person to fix the problems, but the drop-down boxes lose their values. I need to retain this. Quote Link to comment Share on other sites More sharing options...
waterssaz Posted January 13, 2009 Share Posted January 13, 2009 am i right in assuming the page posts back to self until no more errors exist? Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 13, 2009 Share Posted January 13, 2009 $options = array ('One', 'Two', 'Three', 'Four'); echo "<select name=\"number\">\n"; foreach ($options as $optValue) { $selected = ($optValue == $_POST['number']) ? ' selected="selected"' : ''; echo "<option value=\"{$optValue}\"{$selected}>{$optValue}</option>\n"; } echo "</select>\n"; EDIT: Corrected a couple errors Quote Link to comment Share on other sites More sharing options...
louis_coetzee Posted January 13, 2009 Author Share Posted January 13, 2009 yep, waterssaz thats exactly what I am doing. <form name="form" method='post' action=""> Quote Link to comment Share on other sites More sharing options...
waterssaz Posted January 13, 2009 Share Posted January 13, 2009 great stuff, post above beat me to advice. That will do the job great :-) Quote Link to comment Share on other sites More sharing options...
louis_coetzee Posted January 13, 2009 Author Share Posted January 13, 2009 Thanks mjdamato that solves the problem. Quote Link to comment 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.