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

Riadh Rahmi

Senior Web Developer (Drupal & Laravel)

I am a senior web developer, I have experience in planning and developing large scale dynamic web applications especially in Drupal and Laravel.

Web Posts

Search

Page Facebook