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. Link to comment https://forums.phpfreaks.com/topic/140686-how-to-retain-drop-down-menu-selected-state-when-the-page-reposts/ 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? Link to comment https://forums.phpfreaks.com/topic/140686-how-to-retain-drop-down-menu-selected-state-when-the-page-reposts/#findComment-736298 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. Link to comment https://forums.phpfreaks.com/topic/140686-how-to-retain-drop-down-menu-selected-state-when-the-page-reposts/#findComment-736305 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? Link to comment https://forums.phpfreaks.com/topic/140686-how-to-retain-drop-down-menu-selected-state-when-the-page-reposts/#findComment-736308 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 Link to comment https://forums.phpfreaks.com/topic/140686-how-to-retain-drop-down-menu-selected-state-when-the-page-reposts/#findComment-736310 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=""> Link to comment https://forums.phpfreaks.com/topic/140686-how-to-retain-drop-down-menu-selected-state-when-the-page-reposts/#findComment-736315 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 :-) Link to comment https://forums.phpfreaks.com/topic/140686-how-to-retain-drop-down-menu-selected-state-when-the-page-reposts/#findComment-736323 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. Link to comment https://forums.phpfreaks.com/topic/140686-how-to-retain-drop-down-menu-selected-state-when-the-page-reposts/#findComment-736327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.