I am trying to validate a birthdate (provided in 3 separate inputs: day [nac_fecha_d], month [nac_fecha_m] and year [nac_fecha_a]), first to see if it's a valid date and then to see if the person is 18 or older. The problem is everytime I add this block of code to my custom validation, my form gets into event loops with no error message displayed. As hard as I look at this I can't find what's causing it. I'm no PHP expert, so any input will be appreciated.
P.S. Though I guess it's not relevant, I'm using V4 with Joomla 1.6
$trimmed_d = trim ($form->data{'nac_fecha_d']));
$trimmed_m = trim ($form->data{'nac_fecha_m']));
$trimmed_a = trim ($form->data{'nac_fecha_a']));
if ( checkdate($trimmed_m,$trimmed_d,$trimmed_a) )
{
//// Calcular edad ///////////////////////////
$a_dif = date("Y") - $trimmed_a;
$m_dif = date("m") - $trimmed_m;
$d_dif = date("d") - $trimmed_d;
if (($d_dif < 0) || ($m_dif < 0))
{ $a_dif--; }
if ( $a_dif < 18 )
{
$form->validation_errors['nac_fecha_a'] = 'Lo sentimos. Tienes que ser mayor de edad para inscribirte. Si escribiste una fecha de nacimiento equivocada, corrígela por favor.';
$error_count++;
}
}
else
{
$form->validation_errors['nac_fecha_a'] = 'La fecha es incorrecta. Debes escribir día, mes y año. Ej.: 05-09-1988';
$error_count++;
}
P.S. Though I guess it's not relevant, I'm using V4 with Joomla 1.6