Originally posted by TheDefender
Too limited... Using this method, your users can select a day that doesn't exist in a given month...
Right. BUT, using the above method with 3 drop down boxes WITH strtotime for validation, he should be ok.
User enters an invalid date. April 31, 2005. Because there's seperate input boxes, we can build our own date string. Like this:
$userdate = $usermonth . '/' . $userday . '/' . $useryear; // (month, day, year to be numeric form data)
Then, to make sure its a valid date, you could do this:
$testdate = date('m/d/Y', strtotime($userdate));
Now, strtotime() has this bad habit of converting an invalid date into a valid date, even if its not what the user wanted. So, to check if that happened, we can do this:
if($testdate != $userdate)
{
// date validation failed. User entered an invalid date. Return user to form and have them correct it.
} // end if($testdate != $userdate)
At this point, its up to the coder to decide how to handle the failed validation.
DHTML and JavaScript are great, and will make the user experience better, but won't be able to stop those who disable JavaScript and/or are messing with your form.