framework/web/widgets/CActiveForm.php
public static function validate($models, $attributes=null, $loadInput=true)
	{
		$result=array();
		if(!is_array($models))
			$models=array($models);
		foreach($models as $model)
		{
			$modelName=CHtml::modelName($model);
			if($loadInput && isset($_POST[$modelName]))
				$model->attributes=$_POST[$modelName];
			$model->validate($attributes);
			foreach($model->getErrors() as $attribute=>$errors)
				$result[CHtml::activeId($model,$attribute)]=$errors;
		}
		return function_exists('json_encode') ? json_encode($result) : CJSON::encode($result);
	}
public static function validate($models, $attributes=null, $loadInput=true)
	{
		$result=array();
		if(!is_array($models))
			$models=array($models);
		foreach($models as $model)
		{
			$modelName=CHtml::modelName($model);
			if($loadInput && isset($_POST[$modelName]))
				$model->attributes=$_POST[$modelName];
			$model->validate($attributes);
			foreach($model->getErrors() as $attribute=>$errors)
				$result[CHtml::activeId($model,$attribute)]=$errors;
		}
		return function_exists('json_encode') ? json_encode($result) : CJSON::encode($result);
	}
public static function validate ( $ models , $ attributes = null , $ loadInput = true ) { $ result = array ( ) ; if ( ! is_array ( $ models ) ) $ models = array ( $ models ) ; foreach ( $ models as $ model ) { $ modelName = CHtml :: modelName ( $ model ) ; if ( $ loadInput && isset ( $ _POST [ $ modelName ] ) ) $ model -> attributes = $ _POST [ $ modelName ] ; $ model -> validate ( $ attributes ) ; foreach ( $ model -> getErrors ( ) as $ attribute => $ errors ) $ result [ CHtml :: activeId ( $ model , $ attribute ) ] = $ errors ; } return function_exists ( 'json_encode' ) ? json_encode ( $ result ) : CJSON :: encode ( $ result ) ; }
Validates one or several models and returns the results in JSON format.
This is a helper method that simplifies the way of writing AJAX validation code.
@param mixed $models a single model instance or an array of models.
@param array $attributes list of attributes that should be validated. Defaults to null,
meaning any attribute listed in the applicable validation rules of the models should be
validated. If this parameter is given as a list of attributes, only
the listed attributes will be validated.
@param boolean $loadInput whether to load the data from $_POST array in this method.
If this is true, the model will be populated from <code>$_POST[ModelClass]</code>.
@return string the JSON representation of the validation error messages.
Validates one or several models and returns the results in JSON format . This is a helper method that simplifies the way of writing AJAX validation code .