[eluser]CroNiX[/eluser]
The first parameter of set_message must be the same name as the validation method it's being set in or the validator won't be able to retrieve the error message for whatever field it was assigned to, so in this case it would be $this->set_message('date_check').
Cris, I don't think you should convert it to a timestamp in the validation. You should only check whether the supplied date was valid, and that the person was over 18. If the form passes validation (meaning the date was valid along with all other fields), your model should be the one to convert it to a timestamp before it inserts/updates into the db.
Code:
//grab year, month and days fields
$y = $this->input->post('year');
$m = $this->input->post('month');
$d = $this->input->post('day');
//Is the date a valid date?
if ( ! checkdate($y, $m, $d))
{
//set message for invalid date
$this->form_validation->set_message('date_check', 'Birth Date', 'The date you supplied does not seem to be valid.');
return FALSE;
}
//date is valid, check for at least 18 years of age
$birthdate = new DateTime("$y-$m-$d");
$today = new DateTime();
$interval = $today->diff($birthdate);
$years_old = $interval->format('%y');
if ($years_old < 18)
{
//set message for under 18
$this->form_validation->set_message('date_check', 'Birth Date', 'We are sorry; you are under 18 years old.');
return FALSE;
}
//passed
return TRUE;