I have an activeCheckbox on a form that needs to be checked before submitting the page. Pretty simple stuff. But, it is not working as one would expect. I’ve read numerous posts and have also read as much as I could find in the documentation but still can’t get it to work. Even though the checkbox is checked, the page will not submit. I get the validation message notifying me that I should fix the input problems before I can proceed.
Model validation rule:
array('accept_deactivation_terms', 'required', 'requiredValue'=> 1, 'message' => 'Please accept the terms of de-activation.'),
I created a custom validator and I see why the page isn’t validating. $this->accept_deactivation_terms always returns a value of 0 whether the checkbox is checked or not.
public function acceptTerms($attribute,$params)
{
if ($this->accept_deactivation_terms != $params['accepted'])
{
$this->addError($attribute, 'Please accept de-activation terms and conditions!');
}
}
Man, that was it. Unfortunately, I was thinking that yii was doing that behind the scenes. Oh well…live and learn.
I thought that $account and the Account model was the same. Well it is in form but it didn’t contain the form variables/values. We do have to manually assign the form variable/values to the model before validating, correct?
Also, I do see that there are shortcuts to assign form variables to the model.