Hi:
I´m using the ajax module with "standard" CCK fields, everything works as expected but the fields are not "highlighted red" when validation fails. The error message is displayed but the fields are not highlighted.
Scenario:
- Basic validation (check if empty) works ok (highlights red) for fields marked as mandatory.
- Email CCk field (module) - error message displayed but not highlighted.
- Custom validation on custom module calling "form_set_error" also displays error message, but again, won´t highlight in red.
My custom
function validaciones_formularios_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'ficha_candidato_node_form':
$first = array_shift($form['#validate']);
array_unshift($form['#validate'], $first, '_valida_nif_cif_nie');
break;
}
}
function _valida_nif_cif_nie($form, &$form_state) {
$cif=$form_state['values']['field_dni'][0]['value'];
$error=0;
$cif=strtoupper($cif);
if (!ereg('((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)',$cif)) {$error=10;}
for ($i=0;$i<9;$i++) {$num[$i]=substr($cif,$i,1);}
$suma=$num[2]+$num[4]+$num[6];
for ($i=1;$i<8;$i+=2) {$suma+=substr((2*$num[$i]),0,1)+substr((2*$num[$i]),1,1);}
$n=10-substr($suma,strlen($suma)-1,1);
if (ereg('^[ABCDEFGHNPQS]{1}',$cif)) {
if ($num[8]==chr(64+$n) || $num[8]==substr($n,strlen($n)-1,1)){$error=0;} else {$error=-2;}}
if (ereg('^[KLM]{1}',$cif)) {
if ($num[8]==chr(64+$n)) {$error=0;} else {$error=-2;}}
if (ereg('^[TX]{1}',$cif)) {
if ($num[8]==substr('TRWAGMYFPDXBNJZSQVHLCKE',substr(ereg_replace('X','0',$cif),0,8)%23,1) || ereg('^[T]{1}[A-Z0-9]{8}$',$cif)) {$error=0;} else {$error=-3;}}
if (ereg('(^[0-9]{8}[A-Z]{1}$)',$cif)) {
if ($num[8]==substr('TRWAGMYFPDXBNJZSQVHLCKE',substr($cif,0,8)%23,1)) {$error=0;} else {$error= -1;}}
if(strlen(trim($cif))<=0) $error=0;
if($error!=0) form_set_error ('field_dni', t('No es un DNI/NIF válido. Números+letra sin guiones'));
}
"form_set_error" is being executed fine. When I disable the Ajax_ui module the fields are highlighted in red OK.
With the module enabled it somehow stops the "form_set_error" from doing its thing all the way, only the error message is displayed...
And the same goes for the Email CCK field...