Friday, March 18, 2016

Mutliple validation not working

Hi,

I am using cakephp version 3, i am trying to add multiple validation but its not working on password field

$validator = new Validator();
       $validator
                ->requirePresence('email', 'create')
                ->notEmpty('email',['message'=>__('Please enter email address.')])
->add('email', 'email', ['rule' => 'email', 'message'=>__('Please enter valid email address.')])
                ->add('email', 'unique', ['rule' => 'validateUnique', 'provider' => 'table','message'=>__('This Email is already taken.')])
                ->requirePresence('password','create')
->add('password', [
'length' => [
'rule' => ['minLength', 6],
'message' => 'Password need to be at least 6 characters long',
])
               ->notEmpty('password',['message'=>__('Please enter password.')])
->add('password','length',['rule' => ['minLength',6],'message' => __('Password should be minimum 6 character long.')])
->requirePresence('repassword', 'create')
->notEmpty('repassword',['message'=>__('Please enter Confirm Password.')])
->add('repassword','customLength',[
                    'rule' => function($value, $context) {
                        if (trim($context['repassword']) != trim($context['password'])) {
                            return false;
                        }else{
return true;
}
                        return false;
                    },
                    'message' => __('Password and confirm password did not matched.'),
]);
return $validator;


Thanks,
Marcus

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup
 
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
 
Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: