Yii Ajax Validation Multimodel

I succeeded in solving the ajax validation from multiple models, but i would like to have confirms about the logic

Situation: 1 form, 2 models. AjaxValidation ON.

Problem: the first model is correctly validated,and error messages appears without problems on submit (ajax validation). The second model (and all related attributes) are not validated. No error message at all on respective attributes.

Solution: Follow the normal ajax validation procedure, but in this way:




            //$error within end method seems to be the solution.

            if(Yii::app()->request->isAjaxRequest) {

                $error = CActiveForm::validate($model);

                Yii::app()->end($error);

            }



Someone could confirm this behavior? The only counterindication is that in this way all the process seems to stop, so if i would like to use the save method i’ve to double the validation process:




$model = $this->findByAttributes(array('id_sistemazione' => $id_sistemazione));

        $model->attributes = $_POST[__CLASS__];

        if ($model->validate()) {

            $model->save();

        }

        else {           

            if(Yii::app()->request->isAjaxRequest) {

                $error = CActiveForm::validate($model);

                Yii::app()->end($error);

            }

        }