English 中文(简体)
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 );
最佳回答

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.

问题回答

The easiest way is not to try to modify the markup Drupal is spotting out, but instead to change the styles assocaited with the error class.

You can do that without modifying system.css. Simply add a new stylesheet in your theme (or using an existing one!). Use the Cascading nature of CSS to change the way elements with errors appear. Add something like:

.error {
  border: 0;
}

... and you are done.

To target only one specific form, add another selector, like so:

#my-specific-form .error {
  border: 0;
}




相关问题
Drupal Multi-language: Simple strings not translated

I m adding additional languages to a Drupal site that I m building. Getting the translation of content working is fairly easy using the Internationalisation module. Yet, simple things such as date ...

Setting up a WYSIWYG editor for Drupal site users [closed]

Looking through the Drupal contrib modules, and after a few Google searches, it becomes evident that there are any number of choices and combos available to set up a WYSIWYG editor in Drupal. I m ...

Change size of user/password login box

I don t know how to change the size of the login username/password boxes on the drupal site that I m trying to build. I m stumbling through the theming, and don t know where to find the file that ...

How does Drupal provide an edit/review/publish model?

How does Drupal support a means to update and review a website before it is published? Does it only allow you to preview a page at a time before you publish it or is there a way to create a site ...

Term for rotating header

I m looking for terminology that describes this behavior: The header of a web-page contains a different image every time you visit it. Update: It is not an advertisement, but images related to the ...

Has anyone checked out Drupal 7? [closed]

Has anyone checked out a copy of Drupal 7 yet? What do people think? I m pretty excited about the PDO and all of the designers I work with a very excited about the new admin interface/structure. Do ...

热门标签