function persistent_login_form_alter in Persistent Login 7
Same name and namespace in other branches
- 5 persistent_login.module \persistent_login_form_alter()
- 6 persistent_login.module \persistent_login_form_alter()
Implements hook_form_alter().
File
- ./
persistent_login.module, line 118 - Provide a "Remember Me" checkbox in the login form.
Code
function persistent_login_form_alter(&$form, $form_state, $form_id) {
$alter_form = FALSE;
if (substr($form_id, 0, 10) == 'user_login') {
// This is a login form that we want to alter.
$alter_form = TRUE;
}
elseif (substr($form_id, 0, 13) == 'user_register') {
// This is a user register form, but we only want to alter this if
// - Visitors can create accounts and no administrator approval is required.
// - E-mail verification is not required when a visitor creates an account.
// - The form is not being executed by a user administrator.
if (!variable_get('user_email_verification', TRUE) && variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) == USER_REGISTER_VISITORS && !user_access('administer users')) {
$alter_form = TRUE;
}
if (module_exists('logintoboggan') && !variable_get('logintoboggan_immediate_login_on_register', TRUE)) {
$alter_form = FALSE;
}
if (module_exists('user_registrationpassword') && variable_get('user_registrationpassword_registration', USER_REGISTRATIONPASSWORD_VERIFICATION_PASS) != USER_REGISTRATIONPASSWORD_NO_VERIFICATION) {
$alter_form = FALSE;
}
}
if (!$alter_form) {
return;
}
// If the user is reauthenticating, then fill in the name element with the
// user name provided by persistent_login_init().
if (isset($_SESSION['persistent_login_default_user'])) {
// Make sure we still have a 'name' element on this form. Note that someone
// else could have removed it from its own hook_form_alter() implementation.
if (isset($form['name'])) {
$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 (!empty($_SESSION['persistent_login_reauth'])) {
return;
}
// Let's add the "Remember me" checkbox to the login/user register form.
if (isset($form['account']) && is_array($form['account'])) {
$form['account']['persistent_login'] = array(
'#type' => 'checkbox',
'#title' => t('Remember me'),
);
}
else {
$form['persistent_login'] = array(
'#type' => 'checkbox',
'#title' => t('Remember me'),
);
}
// Add an after_build callback that we'll use to adjust the weight
// and tabindex attributes of the "Remember me" checkbox.
if (!isset($form['#after_build'])) {
$form['#after_build'] = array();
}
$form['#after_build'][] = 'persistent_login_form_after_build_proxy';
}