Gii - Why does the performAjaxValidation() call check the form name?


if(isset($_POST['ajax']) && $_POST['ajax']==='registration-form')

{

    echo CActiveForm::validate($models);

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

}

Is there any particular reason why it needs the form name? Why not just check if $_POST[‘ajax’] is set?


if(isset($_POST['ajax']))

{

    echo CActiveForm::validate($models);

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

}

What if you have more then one form on the same page and you want them all to be processed by the same action? For example, you may have registration form with some personal data fields and some company data fields. They are 2 forms, because they belong to 2 different models, but they are displayed and processed by one controller since it’s one registration process. Now, depending on some radio button which allows to choose, lets say “individual customer” or “commercial customer” you can set correct scenarios, and validate correct models. But, in ajax validation request it’s much easier to depend on form name then some checkbox.

I think it just gives you more flexibility and options. Of course you don’t have to use it at all.