I have a form with 3 select fields used for users dob(one for month, day, year). Once the form is submitted, I need to do a check to make sure that if those date fields have been filled, that the data is consistent.
The field is not required, so the data is only handled by the server if all of the fields are filled. But I’m concerned about how to handle the error of when the user submits some of the fields filled, and others not filled. So if the user submits the year, and month, but not the day, and so on and so forth.
Any suggestions, or help will be appreciated.
Use PHP’s checkdate function
Pass in their entered parameters, and it will check that it’s a valid date – as well as telling you about empty parameters, it will also tell you if someone tries the 30th of February.
You just need to check if any of the fields are filled in (as it’s optional); and if that’s so, pass all three into
checkdate.