I am working on Cake 3. I want to create my own validation rule. I want to check if the password field matches the confirm_password field.
This is my code:
public function validationDefault(Validator $validator) { $validator ->add('id', 'valid', ['rule' => 'numeric']) ->allowEmpty('id', 'create') ->add('email', 'valid', ['rule' => 'email']) ->requirePresence('email', 'create') ->notEmpty('email') ->add('email', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']) ->requirePresence('password', 'create') ->notEmpty('password') ->notEmpty('confirm_password') ->add('confirm_password', 'custom', [ 'rule' => function($value, $context) { if ($value !== $context['data']['password']) { return false; } return false; }, 'message' => 'The passwords are not equal', ]); return $validator; }
When I try to "crash" the form-submit, the code is saved and I get no error.
I read http://book.cakephp.org/3.0/en/core-libraries/validation.html#custom-validation-rules but it didn't help .... Anyone?
Thanks!
source share