Question About $This->Adderror

In a page, I have 10 checkboxes.

If the user presses the submit button when there are more than 5 checked, an error message should appear.

I’ve managed to add the validation to the access rules, but the form submits first before showing the error message. I need the message to appear without the form getting submitted. Is there any way to do that?

In the view page I have




echo $form->error($model, 'boxCount'); 



(the form->error should have a corresponding input element right? is there a workaround or something?)

In the model




//inside the public function rules() array

array('boxCount','validateCount'),



Sorry if the explanation seems a bit messy. :(

Try with validateOnSubmit - http://www.yiiframework.com/doc/api/1.1/CActiveForm#clientOptions-detail