Find Out Form ID Easily with Get Form ID Module for Drupal 7

02 May · by Tim Kamanin · 1 min read

"How to find form id in Drupal" is one of the most popular questions, especially for the beginners. More experienced developers know that to find form id you need to either look into the DOM source code or to create your own hook_form_alter() function like this:

function YOUR_MODULE_NAME_form_alter(&$form, &$form_state, $form_id) {
  dpm($form_id);
}

This function will show you all form ids on the page. Being really tired of this approach, I decided to write a little module which will solve the problem once and forever. So I created Get Form ID module which is already available at drupal.org: http://drupal.org/project/get_form_id

The module adds a contextual link to every form that lets you easily find out form's ID and name of hook_form_FORM_ID_alter() hook. More details on how it works you can find in the video below:

Let me know what you think.

Comments

Required for comment verification



tenken

Many frameworks (RoR, Symfony 2, et al) have a development mode debug bar with alot of helpful features. Drupal has the Devel module that has a ton of useful features ...... why isnt this merged into Devel.

Reply · 4 years, 7 months ago
pjcdawkins

You're completely right - I noticed that after watching the full video.

Reply · 4 years, 7 months ago
pjcdawkins

Interesting but perhaps overkill? The module would perform a similar function with just this, surely:

/**
 * Implements hook_permission().
 */
function get_form_id_permission() {
  return array(
'access get form id' => array(
  'title' => t('View form IDs via title attribute'),
  'description' => t("This allows the user to view the form ID in each form's title text."),
),
  );
}

/**
 * Implements hook_form_alter().
 */
function get_form_id_form_alter(&$form, &$form_state, $form_id) {
  if (user_access('access get form id')) {
$form['#attributes']['title'] = t('Form ID: @id', array('@id' => $form_id));
  }
}

Reply · 4 years, 7 months ago
Jurr

Great! It's a smart little trick. beats using drupal_set_message($form_id); in hook_form_alter **

Reply · 4 years, 7 months ago