Sir i want to know that how to validate 2 forms from one model means one form with 2 fields and second with 10 fields so how to validate them saperately.
Hi!
What have you tried?
Some more information would be helpful in getting some support for your query,
Megan
This is my code in model
public function validationDefault(Validator $validator)
{
$validator
->integer(‘id’)
->allowEmpty(‘id’, ‘create’);
$validator
->requirePresence('user_name', 'create')
->notEmpty('user_name');
$validator
->requirePresence('name', 'create')
->notEmpty('name');
$validator
->requirePresence('last_name', 'create')
->notEmpty('last_name');
$validator
->requirePresence('company_name', 'create')
->notEmpty('company_name');
$validator
->requirePresence('company_email', 'create')
->notEmpty('company_email');
$validator
->requirePresence('job_title', 'create')
->notEmpty('job_title');
$validator
->requirePresence('phone_number', 'create')
->notEmpty('phone_number');
$validator
->requirePresence('photo', 'create')
->notEmpty('photo');
$validator
->requirePresence('status', 'create')
->notEmpty('status');
$validator
->requirePresence('password', 'create')
->notEmpty('password');
$validator
->requirePresence('email_verify_code', 'create')
->notEmpty('email_verify_code');
$validator
->requirePresence('email_verified_status', 'create')
->notEmpty('email_verified_status');
$validator
->dateTime('email_verify_date')
->requirePresence('email_verify_date', 'create')
->notEmpty('email_verify_date');
$validator
->integer('invalid_login_count')
->requirePresence('invalid_login_count', 'create')
->notEmpty('invalid_login_count');
$validator
->dateTime('created_on')
->requirePresence('created_on', 'create')
->notEmpty('created_on');
$validator
->dateTime('modified_on')
->requirePresence('modified_on', 'create')
->notEmpty('modified_on');
return $validator;
}
public function validationLogin(){
$validator2 = new Validator();
$validator2
->requirePresence('user_name')
->notEmpty('user_name');
$validator2
->requirePresence('password')
->notEmpty('password');
$validator2
->requirePresence('captcha_code')
->notEmpty('captcha_code');
}
but how i call my validationLogin () from my controller
sir actually i have 2 forms regarding this registration model so the question is how to validate them saperately
https://book.cakephp.org/3.0/en/orm/validation.html#using-a-different-validation-set
basicly you just need a way to know which validation to pass, there are few ways to do it but if i get your question right it should be something like this:
$this->TABLENAME->patchEntity($entity, $this->request->getData(), [
'validate' => $this->request->getData('captcha_code') !== null ? 'login' : 'default'
]);
Thank you very much for help .Now my code is working.Thanks a lot