This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I want to just use the password field but I keep getting "Password confirmation does not match".
I tried:
- Using a hidden field as password confirmation that gets updated with the contents of the password field: only works when not hidden
 - 
adding this in controller and I get the same error:
public function formBeforeCreate($model){ $model->affiliate_user->password_confirmation = $model->affiliate_user->password; } 
What I´m I missing here? Thank you!
Last updated
You might need to use getOriginalHashValue to get the unhashed value.
public function formBeforeCreate($model) {
    $model->affiliate_user->password_confirmation = $model->affiliate_user->getOriginalHashValue('password');
}
                    That didn´t work.
Debuggin the error in the reponse I have also seen this: "The password confirmation field is required when password is present."
It looks like event though I manually add 'password_confirmation' inot the user model it's still required to be a field in the form? Any way to get around that?
Try this
public function formBeforeCreate($model) {
    $model->rules['password_confirmation'] = null;
}
                    That didn't work - I guess validation happens before formBeforeCreate ...
This is what finally worked, found it on another post - you need to extend the funtionality in the boot function inside Plugin.php :
    //Extend Backend user model
    \Backend\Models\User::extend(function ($model) {
        if (!$model instanceof  \Backend\Models\User)
            return;
        $model->bindEvent('model.beforeValidate', function() use ($model) {
            $model->rules = [
              'password_confirmation' => null
            ];
        });
    });
Thanks for your time!!
Last updated
1-7 of 7