I am creating a form that contains a date input field. I have successfully set it up to take the format yyyy-mm-dd, however, when typing in the date staring at the year, my year will accept six values e.g. yyyyyy-mm-dd. This creates two bad user experiences.
- If the user wants to simply type in their date "2020-01-18" then when they type it out it will end up being "202001-12-01" The year has accepted the year and month values and then the month value defaulted to "12" because the day value "18" was entered instead, and the day value ends up being whatever the current date is.
- If the user types in their year "2020" then hit tab to go to the month, it will successfully navigate to the date field where they enter "12". However, if/when they hit tab again to go to the day, it will send them down to the next input field instead of the date, because my current setup will move the input cursor from the month field once it is filled to the day field.
My code for the date input field is:
HTML + PHP
<!-- Date of Birth -->
<label for="dateOfBirth">Date of Birth</label>
<span class="Error">* <?php echo $dateOfBirthErr; ?></span>
<br>
<input type="date" id="dateOfBirth" name="dateOfBirth" value="<?php echo date('Y-m-d'); ?>" />
This same problem occurs on every browser. Thanks, anoyone, for your help!