在Laravel提交表单之前确认密码 [英] Confirm the password before a form submit in Laravel
本文介绍了在Laravel提交表单之前确认密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Laravel 4.2,并且我希望在表单提交之前使用类似模式的方式确认用户的密码,而无需进行实际的提交。如果密码匹配,请执行提交;如果没有,保持在同一页面而不重新加载,这是可能的?
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?
我该怎么做?
推荐答案
在您的模型中加入:
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
}
}
这在你的规则中:
'password' => 'Required|alpha_num|between:6,12|confirmed',
'password_confirmation' => 'Required|alpha_num|between:6,12|same:password',
看看是否有帮助。
这篇关于在Laravel提交表单之前确认密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文