简体   繁体   中英

Confirm the password before a form submit in Laravel

I am using Laravel 4.2 and I want to confirm the user's password before a form submit with something like a modal, without doing the actual submit. If the password matches, do the submit; if not, keep in the same page without doing a reload, it is possible?

How can I do that?

Add this in your model:

public function afterValidate() {
        if (count($this->errors()->toArray())==0 && !empty($this->password) && $this->password!=$this->getOriginal('password')) {
            $this->password = Hash::make($this->password);  // encrypting the password
            unset($this->password_confirmation);    // dropping password confirmation field
        }
    }

This in your rules:

'password' => 'Required|alpha_num|between:6,12|confirmed',
'password_confirmation' => 'Required|alpha_num|between:6,12|same:password',

See, if that helps.

Get the submit button ID, override the onclick() with your own code, bring up your modal that confirms the password, and return false so the form doesn't actually get submitted. When the user clicks OK on your modal, if the password matches then do a form submit from JS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM