hook_form_alter not working

joe_h picture joe_h · May 10, 2010 · Viewed 7.3k times · Source

Im using drupal 6.16. The below code for hook_form_alter is not working. Im simply trying to change the 'Log In' to 'Sign In' on the submit button of the user login form

<?php
//$Id$

function helloworld_form_alter($form_id,&$form) {
  switch ($form_id) {

      case 'user_login_form':

    // Change 'Log in' to 'Sign in'.
    $form['submit']['#value'] = t('Sign in');


      break;
  }
}

Any way to fix this ?

Please help. Thank You.

Answer

Henrik Opel picture Henrik Opel · May 10, 2010

There are two errors in your code:

  1. Your function signature is wrong, as already pointed out by hfidgen (+1). It needs to be yourModuleName_form_alter(&$form, &$form_state, $form_id), so in your example the switch on the form id will never trigger.
  2. You check for the wrong form id. There are two form ids you need to check in this case, and both are different from the one you're using:
    1. user_login_block for the small login form available as a block (commonly used on most pages)
    2. user_login for the explicit login page (usually found under 'user/login')

Both forms are mostly identical in structure, so you can usually change both within the same hook_form_alter implementation - just add another case statement to check for the second version.