Reputation: 21
I created registration form with using gii code generator in yii framework. Gii code generator created all validation rules in fields like fname,lname,email,etc. Now I am trying to put my custom validation rule in all fields. so i need to disable other validation rule in that field which is en-billet by yii framework.
how am I suppose to do that.
Upvotes: 0
Views: 2962
Reputation: 131
You can uncomment/remove the default rules and replace it with your custom rules.
Upvotes: 0
Reputation: 7265
you can also extend class CActiveRecord and overwrite the save()
method which accepts to properties and set the $runValidation
to false.
this is the function in CActiveRecord that needs to be overwrited:
public function save($runValidation=true,$attributes=null)
{
if(!$runValidation || $this->validate($attributes))
return $this->getIsNewRecord() ? $this->insert($attributes) : $this->update($attributes);
else
return false;
}
Upvotes: 0
Reputation: 4607
Assume you have this in your model :
public function rules(){
return array(
array('firstName', 'length', 'max'=>20),
array('lastName', 'length', 'max'=>40),
);
}
this means the validation method checks the length of firstName
and lastName
, and checks that their length should not be greater than 20 and 40.
If you want to remove this rule from validating, you can simply remove the line, and put your custom validation rules in it.
Upvotes: 1