You are here

function betterlogin_form_alter in Better Login 7

Same name and namespace in other branches
  1. 8 betterlogin.module \betterlogin_form_alter()

Implements hook_form_alter().

Autofocus on the username field. Some proper page titles would be nice for a change. User account is a bit boring..

File

./betterlogin.module, line 79
Make the login screens better :).

Code

function betterlogin_form_alter(&$form, &$form_state, $form_id) {

  // Autofocus on the username field.
  // And add some pretty CSS :).
  // And a few other things too...
  if ($form_id == 'user_login' || $form_id == 'user_register_form' || $form_id == 'user_pass' || $form_id == 'user_pass_reset') {
    $form['name']['#attributes']['autofocus'] = 'autofocus';

    // We don't really need descriptions to tell us what we already know...
    unset($form['name']['#description']);
    unset($form['pass']['#description']);

    // Add in some CSS.
    $form['#attached']['css'][] = drupal_get_path('module', 'betterlogin') . '/css/betterlogin.css';
  }

  // Exit if we're not on a target url, since the form may
  // have been rendered programmatically.
  // We don't want to change page titles on other pages.
  // Array of arg(1) url values on target pages.
  $pages = array(
    'login',
    'register',
    'password',
    'reset',
  );
  if (!in_array(arg(1), $pages)) {
    return;
  }
  switch ($form_id) {
    case 'user_login':
      drupal_set_title(t('Login'));
      break;
    case 'user_register_form':
      drupal_set_title(t('Register'));

      // The registration form behaves differently...
      $form['account']['name']['#attributes']['autofocus'] = 'autofocus';
      break;
    case 'user_pass':
      drupal_set_title(t('Forgot your password?'));
      break;
    case 'user_pass_reset':
      drupal_set_title(t('Reset password'));
      break;
  }
}