CActiveForm clientValidation

Hey guys,

I still didn’t exactly understand how the clientValidation exactly works in Yii. Maybe someone could explain this to me or post a link, where this is explained well?

What data is sent to the client and how does the validation work exactly?

Whats a typical use case for this?

In which use cases is it better or possible(?) to use client validation instead of server sided? …

Thanks in advance and sorry if this may be a stupid noob question, I just thought to post this to hopefully finally understand this ;-).

Cheers,

Mayjestic

tried to explain to the login process flow.

try to check on this file: main.php




array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),



This indicates that there is a login method on the controller SiteController and there is method ‘actionLogin’

and it really try to check on siteController




/**

	 * Displays the login page

	 */

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

		}


		// collect user input data

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

		{

			$model->attributes=$_POST['LoginForm'];

			// validate user input and redirect to the previous page if valid

			if($model->validate() && $model->login())

				$this->redirect(Yii::app()->user->returnUrl);

		}

		// display the login form

		$this->render('login',array('model'=>$model));

	}



in the above code, actionLogin will call LoginForm model which was used for validation, giving the name on the label, data etc…

and then display login page in line, with include LoginForm model ($model):




$this->render('login',array('model'=>$model));



then, when the login page is displayed, click the submit button will taken to FormModel class.

because there sintax like this :




<div class="row">

		<?php echo $form->labelEx($model,'username'); ?>

		<?php echo $form->textField($model,'username'); ?>

		<?php echo $form->error($model,'username'); ?>

	</div>



$model is LoginForm class from actionLogin.

and then your input will be validate at:




if($model->validate() && $model->login())

				$this->redirect(Yii::app()->user->returnUrl);