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

'enableAjaxValidation'=>true,


'enableClientValidation'=>true,

But in some reason this does not work for me.

Help!

Hi,

please see this link

http://www.yiiframework.com/forum/index.php/topic/43977-ajax-client-side-validation-without-refreshing-page/page__p__208536__fromsearch__1#entry208536

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

Just like…


$this->render('index',array('model'=>$model),false,true);

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

$this->performAjaxValidation($model);

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);


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


	}


}

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:

'enableAjaxValidation'=>true,


'enableClientValidation'=>true,

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?!

Hi,

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