Anyone help for Model validation,you can check my code and please suggest me?

I have form, when form submit the i want validate the form as following condition.

1 . Phone no. and email field must not empty
2. Either phone no. or email entered then form will submitted.

I have write some code as per doc.

$validator
       ->notEmpty('email', __('Required email is empty.'), function ($context) {
       return !$context['data']['email'];
       });
$validator
       ->notEmpty('phone_no', __('Required phone_no is empty.'), function ($context) {
           return !$context['data']['phone_no'];
       });
$validator->notEmpty('phone_no', __("Required phone_no or email is empty."), function ($context) {
        return !$context['data']['phone_no'] && !$context['data']['email'];
    });

Let me know whats wrong step in this validation.

Well , that Problem is solved by me.

1 Like

how you did solve this problem ?

I have check the cakephp ebook build my function to check that fields for validations

as Following code :-

    $validator        
       ->notEmpty('phone_no', __("Required phone_no or email is empty."), function ($context) {
        if(!$context['data']['phone_no']){
            if(!$context['data']['email']){
                return true;
            } else{
                return false;
            }            
        }else{
            return false;
        }   
    });
1 Like