I'm using version 7 alpha 3 and a custom theme based on seven.

What I want to do is remove the descriptions on the user/login page text fields.
For example, under the password field label it says:
Enter the password that accompanies your username.

I know a couple ways to do it:

  • css: color text same as background (yuck)
  • change the markup based on the name of the text field:
    code from form.inc function theme_form_element($variables)
    if (!empty($element['#description'])) { $output .= ' <div class="description">' . $element['#description'] . "</div>\n"; }
    change in my template.php mytheme_form_element($variables) to
    if ((!empty($element['#description'])) && ($element[#title] != "Password" || $element[#title] != "Username")) { $output .= ' <div class="description">' . $element['#description'] . "</div>\n"; }

But these aren't sound solutions (e.g., maybe I want other Username fields elsewhere to have descriptions).
What I really want is an empty $element['#description'] for the user/login form text fields.

I know where these are defined.
It's in user.module
function user_login($form, &$form_state)
on lines 1816 and 1819 (again, I'm using Drupal 7 alpha 3).

$form['name']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal')));
  $form['pass'] = array('#type' => 'password',
    '#title' => t('Password'),
    '#description' => t('Enter the password that accompanies your username.'),

It's more the process than the result that interests me as this is my first Drupal project,
but I don't know how to remove those descriptions for just the user/login page form without
copying the entire module to my sites/all/modules and modifying it.

Thanks,
nJ

Comments

narayanis’s picture

CSS is one way as you mentioned. Another way is to write a small module that uses hook_form_FORM_ID_alter. You can try using this to set those array values to empty.

njweb’s picture

Excellent.
That was exactly what I needed for two reasons:
1. It answered the question.
2. It inspired my next quest to learn how to write a basic module.

Here's what I did (in case someone else needs to know):

  1. create directory -- sites/all/modules/alterlogin
  2. in that directory make files alterlogin.module and alterlogin.info
  3. alterlogin.module
    <?php
    // remove description from user login form text fields
    function alterlogin_form_user_login_alter(&$form, &$form_state) {
      $form['name']['#description'] = t('');
      $form['pass'] = array('#type'  => 'password',
                            '#title' => t('Password'),
                            '#description' => t(''),
                            '#required' => TRUE,
                           );
    }
    ?>
    
    alterlogin.info
    name = alterlogin
    description = Alter the user login form
    core = 7.x
    files[] = alterlogin.module
    
  4. clear Drupal cache and enable the new module in admin/modules

Worked perfectly.
Thanks!

Dropal-1’s picture

Thanks in two seconds learned how to make a basic module plus this can be used like a "Custom Module" and we can include ALL our custom settings inside one module and with options to choose it a mouse click which functions we want...

I removed "labels", "descriptions" and used "placeholder" (with "Username" and "Password" in the input for login).
I also removed "title", "button" and included "Type and press Enter..." as a "placeholder" in the search box.

Nice idea and thanks for the input mate.

Pratikm96’s picture

Thanks For Your Post.Its very Helpful For me.....

Shepherd348’s picture

Is it possible to simply edit the user module to eliminate the "Enter the password that accompanies your username." ?

samjosein’s picture

All this can also be done from the front.

Try this:

function yourtheme_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#id'] == 'user-login') {
    $form['name']['#description'] = t(''); // Clear the description of name
    $form['pass']['#description'] = t(''); // Clear the description of pass
  }
}
Pratikm96’s picture

Thanks For Your Post.Its very Helpful For me.....

AshwinB’s picture

alterlogin.module and alterlogin.info (in the form of a module) are not working for me. Simply no effect; neither any error nor the descriptions are going. Even when I removed 'Enter the password accompanied...etc..' from user.module, nothing is happening. I tried clearing the cache of my Drupal installation as well as my browser (Chrome). Any suggestions? (for removing the descriptions in username and password fields).

Aporie’s picture

Your post is from a long time ago but if it can help others :

For drupal 8 :

function alterlogin_form_user_login_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $form['name']['#description'] = t('');
  $form['pass'] = array('#type'  => 'password',
                        '#title' => t('Password'),
                        '#description' => t(''),
                        '#required' => TRUE,
                       );
}
samjosein’s picture

This seems all perfect. I got the missing features for my login form.

avinash_thombre’s picture

Create a test custom module to hide the content using hook_form_alter. Write following code inside the test module and refresh the page. The description text will not be visible.

function pfe_test_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'user_register_form' || $form_id == 'user_profile_form') {
    $form['account']['name']['#description'] = t('');
    $form['account']['mail']['#description'] = t('');
  }
}