I’m trying to validate a date input and not quite sure how to go about it. My form has a Day dropdown (1-31 with empty default), Month dropdown (1-12 with empty default) and a Year text input.
The date is not required (all inputs can be empty). Other valid combinations are:
Year only (format YYYY)
Year and Month
Year and Month and Day
So Year and Day with no Month selected would be invalid.
The db table stores the value in a single column ("date_acquired") using the format (YYYYMMDD). So before being saved, the 3 inputs need to be combined (this part I can do).
I’m wondering how I validate the date inputs on submission and then remove them when I do the assignment for saving? How should I validate the date inputs as a group?
Thanks for your suggestions. Some further questions regarding your solution, how do the values for $day, $month and $year get assigned?
Also, how does the validate method know what ‘date_acquired’ is? Because it wouldn’t be in $_POST (I was thinking I’d have the form elements name date_acquired_day, date_acquired_month and date_acquired_year.