hello im trying to add rule for non attribute element of a model.
i did not try to add it as a new attribute discussed as here.
i added a checkbox in a registration form. i defined a new public property for it:
then i defined a new rule in rules method
array('policy', 'terms', 'val'=>1),
i saw this in docs:
class MyValidator extends CValidator
protected function validateAttribute($model,$attribute)
if($value has error)
then i wrote a similar code:
class terms extends CValidator
protected function validateAttribute($model, $attribute)
$errorMessage = "You must agree with the Terms and Conditions!";
$value = $model->$attribute;
if($value !== $this->val)
the problem is:
since this is a non attribute element
is returning null.
i tried several things but i could not come up with something meaningful (shame on me )
but funny thing is i can see the error message now. in every submit whether checkbox checked or not