Hi all,
I have a model in which I have array of validation rules.
I add in those rules, a specific rule and I provide the function which does this verification.
My function returns true in case of it is ok and false in case it is not ok.
However when I validate the model, the validation rule is always OK whatever the test I do. It seems that returning true or false has no effect on the validation of the model.
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('email, password', 'required','on'=>'login,modify'),
array('email,password,amaCode','required','on'=>'register'),
//array('is_active', 'numerical', 'integerOnly'=>true),
array('email', 'length', 'max'=>100),
array('email', 'email'),
array('email','unique'),
array('password', 'length', 'max'=>300),
array('amaCode', 'length', 'max'=>15),
array('password', 'compare', 'compareAttribute'=>'password_repeat','on'=>'register,modify'),
array('amaCode', 'validateRegister', 'on'=>'register'),
);
}
AND THE FUNCTION is only intended to compare the code given in a form to the code in the database
public function validateRegister($attribute,$params) {
$query = Yii::app()->db->createCommand()
->select('*')
->from('tbl_info_ama')
->queryRow();
// Comparer le code ama à celui en database
if(isset($_POST['User'])) {
$model->attributes=$_POST['User'];
if ($this->amaCode === $query['code_ama']) {
return true;
}
else
return false;
}
}
What is the reason why whatever the code I give in the form (same or not the same compared to the one in the database) the validate() function always return OK
thanks