Adding class attributes to form elements
Drupal 6 is quite meticulous with its forms and other markup when it comes to assigning CLASS
and ID
attributes. This ensures that various page elements can be individually targeted either via CSS or JavaScript and thereby manipulated as necessary. This is, however, not true all the time and circumstances sometimes require a little further customization.
In this recipe, we will assign class attributes to the Search module's textfields and use them along with a pinch of jQuery to improve usability in situations where the theme's search box is visible along with the module's input form.
Getting ready
We will be using the mysite module created earlier in this book to hold an implementation of hook_form_alter()
. Since we are playing with the Search module, it is assumed that the module is enabled and that the site's content has subsequently been indexed. The current theme's search-box feature should also be enabled via its configuration page.