Hooking into the user login block to modify prefill default text in username and password I am having problems getting a custom module to recognize the user login block.

Ultimately I need my user login block to only show the username and password fields, without any labels. Instead of labels I need to prefill the form fields with the words 'username' and 'password' and have this text disappear onfocus. This drupal answers question demonstrates how to do this with the search block and a custom module. I have been able get this to work without any problems.

I have tried to do a similar thing with the user login block.

First of all i used this to get the form id:

function custom_prefill_login_form_alter(&amp;$form, $form_state, $form_id) {

 // uncomment to get form id
 drupal_set_message("Form ID is : " . $form_id);
 }


This returns Form ID is : user_login_block for the login block page
and
it returns Form ID is : search_block_form for the search block

When on a page with the search block enabled I can use this:

if ($form['#id'] == 'search-block-form') {  
    dpm('search-block-form showing');
}


but when on the user login block page this doesn't work. Neither of these show anything in the message area:

 if ($form['#id'] !== 'user-login-block') {  
     dpm('user-login-block showing');
 }

 if ($form['#id'] !== 'user_login_block') {  
    dpm('user_login_block showing');
}


I am very confused as to why this isn't working. I would appreciate being shown how to write an if statement that targets the user login block.

My entire function is:

function custom_prefill_login_form_alter(&amp;$form, $form_state, $form_id) {

    // uncomment to get form id
    drupal_set_message("Form ID is : " . $form_id);

    if ($form['#id'] !== 'user-login-block') {  
          dpm('user-login-block showing');
      }

    if ($form['#id'] !== 'user_login_block') {  
          dpm('user_login_block showing');
      }

    if ($form['#id'] == 'search-block-form') {  
          dpm('search-block-form showing');
          $search_text = 'Your search text here';
          $form['search_block_form']['#default_value'] = $search_text;
           $form['search_block_form']['#attributes'] = array(
          'onfocus' =&gt; "if (this.value == '$search_text') {this.value = '';}",
          'onblur' =&gt; "if (this.value == '') {this.value = '$search_text';}");
      }

  }
To target a specific form you can use hook_form_FORM_ID_alter(), e.g.:

function MYMODULE_form_user_login_block_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['foo']['#default_value'] = 'bar';
}


If you'd rather do it all in one alter hook though, use the provided $form_id parameter instead of $form['#id']...it's guaranteed to be the right one.

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'user_login_block') {
    $form['foo']['#default_value'] = 'bar';
  }
}


As a side note, it's probably not working at the moment because you're negating the condition:

if ($form['#id'] !== 'user-login-block') {  


should be

if ($form['#id'] === 'user-login-block') {