I’m creating a simple registration page:
<?php
$firstName = $_POST['firstName'];
?>
<form action="registration.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>
<b>First name:</b>
</td>
<td>
<input type="text" name="firstName" size="30" maxlength="400" value="<?php echo $firstName; ?>" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</form>
If the user enters an invalid first name (ex. too short, or weird symbols), the page reloads with an error message shows up to tell them that they have to re-enter their name HOWEVER, the value of the text field is what they most recently entered. This way whenever a user doesn’t pass validation, they don’t have to re-enter all the fields in the form.
What’s a good way to remember what the user entered for a drop down menu? The problem for me is that the option value is different than the text inside the option tag. So when I use the above approach, if I select “Mar” if in invalid submission occurs, ’03’ appears in the dropdown menu.
<select name="birthdayMonth">
<option value="-1">Month:</option>
<option value="01">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="06">Jun</option>
<option value="07">Jul</option>
<option value="08">Aug</option>
<option value="09">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
At the top:
$birthdayMonth = $_POST['birthdayMonth']In the
select: