user1234 user1234 - 6 months ago 46
PHP Question

How to apply validation?

Hi have a table in which i have many fields but i need to put validation in fields.


all these are saved in same database i want to apply unique validation on email and mobile. Such that no user and admin has same mobile or email. I used following rule but it don't solve my problem. Please help. Any help is appreciated.

public function rules()
'message'=>'{attribute} already exist')


It works only for user's and admin. but i want no new user or admin has same mobile no and not same email.
but this validation not matching admin_email with user_email and admin_mobile with user_mobile.


First you have to add one condition for check if you have add validation in controller.

public function actionname(){
       $model = new modelname; // model name enter here 
       $model->setattributes($_post['modelname']) // set record into model 
     }else{ ... }