I want to alter the username label. Instead of username, I want to change it to User ID.

I've written the following code to perform this function, but I'm not sure how to implement it. When I implement it in the page that contains the login block, nothing happens.

function lae_form_user_login_form_alter(&$form, &$form_state, $form_id) {
 $form['user-login-form']['edit-name']['#title'] = t('User ID');

Will this actually work? If it will, how do you implement it?

2 Answers 2


Your code needs to go inside a custom module. Assuming your module is called lae then you just need to make one or two small changes to your code:

function lae_form_user_login_form_alter(&$form, &$form_state, $form_id) {
  $form['name']['#title'] = t('User ID');

The edit- prefix that you get from the element's ID in HTML is actually provided by Drupal automatically, it's not the name of the key in the form array that identifies the element. Also the elements (at least for this particular form) will normally be at the root of the array so you don't want to reference $form['user-login-form']['edit-name'] (as it most likely doesn't exist).

I would advise downloading and installing the Devel module and using the dpm() function to print a nice representation of your form array to the screen, so that you can inspect it and see the correct array keys you'll need to target to effect a certain element.

// Add this to your form alter function:
  • Thank's for your prompt answer. LAE is actually the name to a zen sub theme that I'm using. I actually added the code to the "template.php" file. When you say, "custom module," do you mean that I need to build my own module and place it in the "/sites/all/modules" folder?
    – dqfan2012
    Apr 17, 2012 at 14:29
  • 1
    hook_form_alter() does get called for themes as well as modules as it goes, so all you need to is put this code in your theme's template.php file, clear Drupal's cache and you should be good to go. Clearing the cache is probably the only bit you've missed so far. To make sure the hook is being called just add drupal_set_message('Hook called'); into the function and see if you get the message on the site.
    – Clive
    Apr 17, 2012 at 14:30
  • Once again, thanks. I actually have multiple modules already installed in Drupal 7 to assist with creating this site. I had devel installed before posting this question. I find page_title, metatags, pathauto, ctools & admin_menu to be quite nice additions.
    – dqfan2012
    Apr 17, 2012 at 14:33
  • I'm still very new to drupal, so you'll have to excuse me. How do you call the above function? Do you just write the name out lae_form_user_login_form_alter() .... and if you call this function, how do you know what to use for the parameters of the function>
    – dqfan2012
    Apr 17, 2012 at 14:45
  • 1
    It's one of Drupal's 'hooks', you define the function with a specific name (in this case THEMENAME_form_alter), and Drupal will automatically pick it up for you when the caches are next rebuilt, and the system will call the function when it's appropriate. Each core hook (and many contrib hooks) are well documented (search Google for hook_form_alter, hook_page_alter, hook_menu, etc.). You'll find the function signatures on the individual docs pages
    – Clive
    Apr 17, 2012 at 14:51

You can use the String Overrides module.

Provides a quick and easy way to replace any text on the site.



  • Easily replace anything that's passed through t()
  • Locale support, allowing you to override strings in any language
  • Ability to import/export *.po files, for easy migration from the Locale module
  • Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.
  • The String Override module doesn't allow to decide where the string should be replaced. It changes every occurrence of username whenever it is passed to t().
    – apaderno
    Jun 18, 2020 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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