I have used custom_module_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id); I get the form ID of other forms, but I don't get the login form $form_id inside the hook.

  • Welcome to Drupal Answers! You are simply stating facts, without asking any explicit question. What exactly is not clear in what you are trying? What form ID are you expecting the login form should have?
    – apaderno
    Commented Jun 30, 2016 at 9:26

2 Answers 2


Try clearing cache and then visiting login page again, that should show Form ID. It will be hidden again when you refresh login page.

use \Drupal\Core\Form\FormStateInterface;

 * Implements hook_form_alter().
function [MODULE_NAME]_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  echo $form_id;
  switch ($form_id) {
    case 'user_login_form':
      // Do your code here to alter login form.
function MYMODULE_form_user_login_form_alter(&$form, &$form_state, $form_id) {
  // you code here

Not the answer you're looking for? Browse other questions tagged or ask your own question.