how m i going to validate form with javascript n jquery with the use of yii

hi there,

i required to validate the previous textfield upon focusing on the current textfield with javascript but at the same time make full use of yii framework.

Model:



public function rules()


{


     return array(


          array('firstname', 'required'),


     );


}


Controller:



public function actionValidate()


{


     $form = new MyForm();





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


     {


          $form->attributes = $_POST['MyForm'];


          $form->validate();


     }


}


how m i going to code the javascript part so much so that i could make use of CHtml::script n CHtml::ajax, n also for controller side what else need to change? i do noe that for a pure jquery scripting will be:



$(document).ready(function()


{


     $(':input').focus(function()


     {


          $.ajax(


          {


              // url, data, etc.


          });


     });


}


thanks in advanced.

you would use the clientscript class and either add you code as a file or as a string to probably ready to initialize your validation stuff then to body for the validation functions. You might look at validation extension for Yii it takes the rules for forms and build JS validation rules. or if you want you can use the jquery validation plugin directly instead of using the extension.

hi rfenner,

do you have any examples to show? i did some search on the use of cclientscript using google, can't find any the suits my problem.

thanks.