Drupal - How can I find the form ID of a form?

Finding FORM ID without installing module

Finding the Form ID is very easy no need to install modules and all

STEP 1: Open you from go to its edit page(OR inspect your form).

STEP 2: if its a node form find "node-form" in the inspect element

Finding the form id check you are in the form element.

STEP 3: see attached image the highlighted green text is the ID of the form

STEP 4: IMPORTANT Finally if you want to use it in hook_form_alter() replace the hypen with underscore

For example: yourform_id_with_content_type_name_form

Like wise you can find id of any form in drupal all you have to do is inspect->find form element and search for the ID attribute and use it

Hope it helps :)


Try printing the form variables with PHP function print_r.

function hook_form_alter(&$form, &$form_state, $form_id) {
  print_r($form);
}

When you visit the page the form is on, the variables (and name) will be displayed.

An easier way of accessing (or rather viewing) the information would be using dpm() function provided by the Devel module. You can use it in the same way you would use print_r.


If your webform is located at "www.mydomain.com/node/351" then your form ID will be "webform_client_form_351". So, whatever your nid is - that's your form ID.

Tags:

Forms