[eluser]adamp1[/eluser]
I was writing a new form for my website, when I needed to check first if a date was in the correct format, then if it was not in the past so I created the following code:
Code:
$rules['expire'] = 'callback_dateformat|callback_dateinpast';
function dateformat($str)
{
$this->validation->set_message('dateformat','The %s is not in the format DD/MM/YYYY');
return (ereg('[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}',$str)) ? TRUE : FALSE;
}
function dateinpast($str)
{
$this->validation->set_message('dateinpast','The %s cannot fall in the past');
list($day,$month,$year) = explode('/',$str);
$unixtime = mktime(0,0,0,$month,$day,$year);
return ($unixtime>=time()) ? TRUE : FALSE;
}
(Of course this isn't how my file is structured)
So now if I don't enter a correct date I get the first error, but if I enter correct date but one in the past I don't get an error. Now I know were the problem is. If I have the following field rule.
Code:
$rules['expire'] = 'required|callback_dateformat|callback_dateinpast';
It will work, since in Validation.php Line 279 it only moves on if the result is TRUE and its required. Otherwise it cuts out. Now its fine when only one callback is used but with two it breaks.