Jump to content

still have user input after exit because of errors


dadamssg

Recommended Posts

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";

 

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>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.