edfou Posted September 27, 2013 Share Posted September 27, 2013 Can view form here. Need to add sticky quality! http://www.cmfsc.ca/forms/FormsTesting.php Here's my code. How do I modify to add sticky quality, to retain values after Submitting form? <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"><? $startTime = mktime() - (2 * 3600); $endTime = mktime() - (14 * 24 * 3600);print '<select name="newgameday">';for ($i = $startTime; $i >= $endTime; $i = $i - 86400) {$thisDate = date('l F jS Y', $i);print "<option value=\"$thisDate\">$thisDate</option>\n";}print '</select>';?><input type="submit" name="submit" value="Submit" /></form> Thanks for any help!! Quote Link to comment https://forums.phpfreaks.com/topic/282469-sticky-dropdown-menu-for-dates-from-today-to-minus-14-days/ Share on other sites More sharing options...
Solution Ch0cu3r Posted September 27, 2013 Solution Share Posted September 27, 2013 When the form is submitted you need to compare the posted value to the value you're making in your for loop. If the values match add a selected attribute to the <option> tag. <form action="" method="post"> <select name="newgameday"> <? $startTime = mktime() - (2 * 3600); $endTime = mktime() - (14 * 24 * 3600); for ($i = $startTime; $i >= $endTime; $i = $i - 86400) { $thisDate = date('l F jS Y', $i); // nothing selected by default $selected = ''; // if the form is submitted. // Check that the posted value is the same as this value // if is the same set it to selected. if(isset($_POST['newgameday']) && $_POST['newgameday'] == $thisDate) $selected = ' selected'; // added the selected attribute here \/ print "<option value=\"$thisDate\"$selected>$thisDate</option>\n"; } ?> </select> <input type="submit" name="submit" value="Submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/282469-sticky-dropdown-menu-for-dates-from-today-to-minus-14-days/#findComment-1451358 Share on other sites More sharing options...
fastsol Posted September 27, 2013 Share Posted September 27, 2013 This tutorial will explain how to do this http://amecms.com/article/Retaining-Drop-down-Selection-After-Form-Submit Quote Link to comment https://forums.phpfreaks.com/topic/282469-sticky-dropdown-menu-for-dates-from-today-to-minus-14-days/#findComment-1451401 Share on other sites More sharing options...
edfou2 Posted September 28, 2013 Share Posted September 28, 2013 Lost my first login, had to create a new account. Anyway thanks a lot for both of your help!! Ch0cu3r your code is fantastic. Copy and Paste and I'm up and running. A two minute solution after many many hours. Thank you so much! Great Forum! Cheers Ed Quote Link to comment https://forums.phpfreaks.com/topic/282469-sticky-dropdown-menu-for-dates-from-today-to-minus-14-days/#findComment-1451500 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.