Finding the form ID of a form
Drupal's Form API uses an ID field to identify each form. These IDs are usually automatically generated based on the function declaring the form and are therefore unique. Consequently, they can be used to identify specific forms either while altering the form using hook_form_alter()
or for theming purposes using JavaScript and CSS.
In this recipe, we will look at ways to identify the Form ID of a form.
Getting ready
We will be using the Devel module to retrieve and display the form ID, and the Search module to simulate a situation where there is more than one form on a page. Additionally, we will be adding our code to the mysite module created earlier in this book. It is assumed that all these modules have been installed and are enabled.
Furthermore, the search box for the current theme should be enabled from the theme's configuration page.
How to do it...
Navigate to the mysite module folder at sites/all/modules/mysite
to perform the following steps:
Locate the file...