Validation Without Reloading The Page

I have a page with both CActiveForm and my own complex JavaScript code which allows to enter tabular data (it is then is encoded into a string and this string is sent in submit by setting the value of a hidden field to this string).

The trouble is that if there is a validation error when submitting the form, my tabular data is lost and this is very bad.

Can we make validation without reloading the page?

I experimented with



But in some reason this does not work for me.



please see this link

or make sure when you page render you can pass the third and fourth paramers is false,true.

Just like…


Please check whether You have wrote this code in that action of the controller


and also check that the name of your form should be in this action of ur controller

protected function performAjaxValidation($model)


	if(isset($_POST['ajax']) && $_POST['ajax']==='name_of_form')


		echo CActiveForm::validate($model);




But CController->render() has only three arguments while you suggest to pass four arguments. I don’t understand.

I’ve uncommented $this->performAjaxValidation($model); both in create and update handler and ensured that the function performAjaxValidation() is as you’ve specified. I’ve also set in CActiveForm options:



But when I click Submit, the form nevertheless reloads (I think it reloads, because the browser window scrolls to the top of the page when I click Submit, and also because that my tabular data (see above) is lost when clicking Submit).

Is it possible to do validation without reloading the page?!


For your problem… the best solution is to not use the 4th parameter as "true"… and to register all the needed JS/CSS in the main view or at first non-ajax call…

please see this…

CControler::render() has a third parameter that if set to true returns the rendering result instead of displaying it - http://www.yiiframew…r#render-detail