You are here

function persistent_login_form_alter in Persistent Login 5

Same name and namespace in other branches
  1. 6 persistent_login.module \persistent_login_form_alter()
  2. 7 persistent_login.module \persistent_login_form_alter()

Implementation of hook_form_alter().

File

./persistent_login.module, line 112

Code

function persistent_login_form_alter($form_id, &$form) {
  if (substr($form_id, 0, 10) == 'user_login') {
    $element = array(
      '#type' => 'checkbox',
      '#title' => t('Remember me'),
    );
    if ($_SESSION['persistent_login_default_user']) {
      $form['name']['#default_value'] = $_SESSION['persistent_login_default_user'];
    }
    unset($_SESSION['persistent_login_default_user']);
  }

  // Don't show Remember Me checkbox if we're reauthenticating to
  // access a protected page unless I change the code to delete the PL
  // session if the user does not check the box.
  //
  // This variable is not unset until login succeeds so if the user
  // mistypes the password Remember Me will stay hidden.  Since this
  // can only get set within a valid PL session, there is no risk of
  // it hiding Remember Me for a non-logged-in user.
  //
  if ($_SESSION['persistent_login_reauth']) {
    return;
  }
  if ($form_id == 'user_login') {
    $form['persistent_login'] = $element;
    $form['persistent_login']['#attributes'] = array(
      'tabindex' => 3,
    );
    $form['op']['#attributes'] = array(
      'tabindex' => 4,
    );
  }
  else {
    if ($form_id == 'user_login_block') {

      /* there must be a better way! */
      $tmp = $form;
      $form = array();
      foreach ($tmp as $k => $v) {
        $form[$k] = $v;
        if ($k == 'pass') {
          $form['persistent_login'] = $element;
        }
      }
    }
  }
}