Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

Question

How to add “Remember me” checkbox to login form in Drupal 8?

Solution

/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
    if ($form_id == 'user_login_form') {
        $form['remember_me'] = [
            '#type'          => 'checkbox',
            '#title'         => t('Remember me'),
            '#default_value' => FALSE,
        ];
    }
}

Screenshot

remember me login form

 

Tags :

Comments

Submitted by Armando (not verified) on Sat, 08/29/2020 - 01:53 Permalink

This doesn't really have any useful functionality. The purpose of "remember me" checkbox, is that it can store the username and/or password somewhere, so when a user goes back to the website they don't have to re-enter it.
Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon