Hi,
I know I saw this either in the forum or in the docs but I just can't seem to find it anymore. There was an example of validating two password fields, the password and the repeated password using an Identical Validator.
Could someone please share the link below or possibly give an example of this in practice?
I have this code:
// New Password
$newPassword = new Password('newPassword');
$newPassword->setLabel('New password');
$newPassword->setAttribute("placeholder","Password");
$newPassword->addValidator(new StringLength([
'min' => 10,
'max' => 45,
'messageMaximum' => 'Password is too long, max 45 characters',
'messageMinimum' => 'Password is too short, min 10 characters'
])
);
$this->add($newPassword);
// Repeat Password
$repeatPassword = new Password('repeatPassword');
$repeatPassword->setLabel('Repeat new password');
$repeatPassword->setAttribute("placeholder","Password");
$repeatPassword->addValidator(new Identical([
$newPassword->getValue() => $repeatPassword->getValue(), // <- Doesn't work
'message' => 'Passwords must match'
])
);
$this->add($repeatPassword);
The code above doesn't seem to work as I'm not sure how to get the value from the one to compare to the other.