[eluser]CoffeeBeanDesign[/eluser]
I've written a function to add a 'warning' class to fields which have failed validation. It is not fully tested and I'd appreciate your input - I was thinking of maybe adding in the ability to limit it to only add the class to the first field with an error but this might need some more hacking.
The first bit just adds in one line to the _parse_form_attributes to call the error check. The second function takes a look at the validation data and if the field failed, changes the class attribute.
Code:
function _parse_form_attributes($attributes, $default)
{
$attributes = _set_form_error_class($attributes);
...
Code:
function _set_form_error_class($attributes = array())
{
if ( ! isset ( $attributes['name'] ) ) return $attributes;
$OBJ =& _get_validation_object();
$field_data = $OBJ->_field_data;
if ( ! isset ( $field_data[$attributes['name']] ) ) return $attributes;
if ( $field_data[$attributes['name']]['error'] != '' ) :
if ( isset($attributes['class'] ) ) :
$attributes['class'] .= ' warning';
else :
$attributes['class'] = 'warning';
endif;
endif;
return $attributes;
}
... what do you think??