I was re-reading the yii tutorial on Forms today and realized I’m utterly confused as to how the AJAX-based validation works. Consider this working code (default app generated by the yii command-line tool)
public function actionLogin()
{
$model=new LoginForm;
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
...
}
We create a new instance of LoginForm, and then send this model (without populating the models attributes) to the CActiveForm::validate() method.