drupaldrupal-themesdrupal-themingdrupal-forms

Remove the red outline on form elements that fail validation in drupal


When a drupal form fails validation, it is redrawn with the elements that failed validation surrounded in a red border. Drupal does this by adding the error class to the input elements, and specifing a 2px red border on input.error elements in system.css.

Without modifying this stylesheet, how can I remove the red border on a specific form only, while using the default behavior on the rest of the site?

I believe the solution might require using a custom theme_form_element, but I can't figure out how to customize a single form only.

Note that I would like to do this without having to resort to this jQuery trick (which does work):

$("#edit-name").removeClass('error');

Solution

  • You will need to remove the error class from the form items. This can be done by overwriting the theme functions, in theme_textfield, theme_textarea ... (there is one for each type)

    Take a look at $element['#attributes']['class'] which contains the error class.

    EDIT
    To do it for a specific form element or form you can use the #theme attribute or either form or element you want to change the theming function for.