Yii has inbuild validation for forms inside Model. You can define Rules for each and every fields according to the requirements . But it may little tricky to use yii validations outside the model . Today i am going to explain How can we implement yii validation outside the model . Here is an example .
Step 1): First of all we need to create a custom class for validation which extends CFormModel like this

class MyValidator extends CFormModel {
    public function __get($name) {
        return isset($_POST[$name])?$_POST[$name]:null;
    }

    static function myValidate( Array $rules ) {
        $dummy = new MyValidator();

        foreach($rules as $rule) {
            if( isset($rule[0],$rule[1]) ) {
                $validator = CValidator::createValidator( 
                     $rule[1], 
                     $dummy, 
                     $rule[0], 
                     array_slice($rule,2) 
                );
                $validator->validate($dummy);
            }
            else { /* throw error; */ }
        }
		return $dummy;
    }
}

Step 2): Now we can use this class to validate our fields . here is an example

public $errors;
public function actionConfiguration()
{
	if(Yii::app()->request->isPostRequest)
	{
		$model=MyValidator::myValidate($this->validConfiguration());
		if(!$model->hasErrors())
		{
			// your logic here
			
		}else
		{
			$this->errors=$model->getErrors(); 
		}	
	}
	$this->render('configuration',array('data'=>$data));
}

Step 3: Create html form in the view file .like this

<?php echo CHtml::beginForm(); ?>
<div class="row">
	<?php echo CHtml::textField('fieldname','',array('value'=>'your value')); ?>
	<?php echo $this->displayerror('fieldname'); ?>
</div>
<div class="row">
	<?php echo CHtml::textField('fieldname2','',array('value'=>'your value')); ?>
	<?php echo $this->displayerror('fieldname2'); ?>
</div>
<?php echo CHtml::endForm(); ?>

Step 4: Now create an error display function displayerror

public function displayerror($key)
{
	if(isset($this->errors[$key][0]))
	return $this->errors[$key][0];
	else
	return '';
}
http://codingbin.com/wp-content/uploads/2016/03/Untitled-1-copy.jpghttp://codingbin.com/wp-content/uploads/2016/03/Untitled-1-copy-150x150.jpgdevidframeworksphpYiimvc,yii,yii-modelYii has inbuild validation for forms inside Model. You can define Rules for each and every fields according to the requirements . But it may little tricky to use yii validations outside the model . Today i am going to explain How can we implement yii validation outside the...coding, php, wordpress, yii, cakephp, and  jquery

Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request