Adding error class to Webform fields I have a Webform which I'm validating implementing the _validate event (i.e. altering $form["#validate"] by adding a custom validator which accepts &amp;$form and &amp;$form_state).

In my code I have something like this:

if ($nombre &amp;&amp; !CasabacaS3SValidaciones::validarLongitud($nombre, 30))
{
    form_set_error('columnas][datos_personales][nombre', t('El nombre no debe superar 30 carácteres'));
    //what should I put in THIS LINE, replacing this comment, to add the error class?
}


I have no clue about adding the "error" class (e.g. fields marked as required have class "required", and also class "error" when the field is not set). How can I alter the field (take this example field in the form_set_error and assume input variables are &amp;$form and &amp;$form_state) so I can add the error for display?

NOTE: I'm seeking to add the "error" class to the fields, and NOT to the wrapping divs (i.e. those divs having form-item class).

(If a quick solution involves themes, please attach a link so I can read about because i'm banging my head about drupal yet, i'm a total n00b :s).
You could use a preprocess functions in your theme for this. You can add preprocess in your template.php.

function mytheme_preprocess_textfield(&amp;$vars) { // OR preprocess_field.

  $vars['#attributes']['class'][] = 'test' ;
}


Check the $vars parameter for values that may help you determine the logic. For examples, just search your code base for preprocess_textfield or preprocess_field. For more inf