dadamssg Posted March 23, 2009 Share Posted March 23, 2009 I'm trying to figure out how to have selection lists have users selections still there when i quit a script because the user doesn't input valid data. You can use this for text fields, but what about selection list? Last Name<input type="text" name="lastname" value="<?php echo @$lastname ?>" size="16" maxlength="14"><br> such as <select name='smonth'> <option value=01>Jan <option value=02>Feb <option value=03>Mar <option value=04>Apr <option value=05>May <option value=06>Jun <option value=07>Jul <option value=08>Aug <option value=09>Sep <option value=10>Oct <option value=11>Nov <option value=12>Dec </select>\n <select name='sday'> <option value=01>1 <option value=02>2 <option value=03>3 <option value=04>4 <option value=05>5 <option value=06>5 <option value=07>7 <option value=08>8 <option value=09>9 <option value=10>10 <option value=11>11 <option value=12>12 <option value=13>13 <option value=14>14 <option value=15>15 <option value=16>16 <option value=17>17 <option value=18>18 <option value=10>19 <option value=20>20 <option value=21>21 <option value=22>22 <option value=23>23 <option value=24>24 <option value=25>25 <option value=26>26 <option value=27>27 <option value=28>28 <option value=29>29 <option value=30>30 <option value=31>31 </select>\n"; Link to comment https://forums.phpfreaks.com/topic/150661-still-have-user-input-after-exit-because-of-errors/ Share on other sites More sharing options...
dadamssg Posted March 23, 2009 Author Share Posted March 23, 2009 anyone? Link to comment https://forums.phpfreaks.com/topic/150661-still-have-user-input-after-exit-because-of-errors/#findComment-791726 Share on other sites More sharing options...
lonewolf217 Posted March 23, 2009 Share Posted March 23, 2009 compare the submitted item to each option. if they match, just add selected="selected" to the option tag Link to comment https://forums.phpfreaks.com/topic/150661-still-have-user-input-after-exit-because-of-errors/#findComment-791741 Share on other sites More sharing options...
dadamssg Posted March 23, 2009 Author Share Posted March 23, 2009 not quite sure i follow, could you show an example? Link to comment https://forums.phpfreaks.com/topic/150661-still-have-user-input-after-exit-because-of-errors/#findComment-791867 Share on other sites More sharing options...
lonewolf217 Posted March 23, 2009 Share Posted March 23, 2009 Basically it would be far easier if you had your SELECT options in an array. here is the basic concept <?php echo "<SELECT name=\"month select\">"; $array = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dev); foreach($array as $month) { //if the current month matches the month from the form ($_POST) then echo selected if(strcasecmp($month,$_POST['month'])) { echo "<OPTION selected=selected>".$month."</option>"; } else { echo "<OPTION>".$month."</option>"; } echo "</select>"; } Link to comment https://forums.phpfreaks.com/topic/150661-still-have-user-input-after-exit-because-of-errors/#findComment-791872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.