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(&$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(&$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' => "if (this.value == '$search_text') {this.value = '';}",
'onblur' => "if (this.value == '') {this.value = '$search_text';}");
}
}