econditionalvalidator EConditionalValidator - Execute a rule if others have been previously passed.

  1. Introduction
  2. Usage
  3. Change Log
  4. Resources


I had a validation challenge long time a go. The challenge was that I had to validate an attribute only if other attributes where of certain values or fulfilled some rules. For example, in order to validate for an attribute to be an email I needed to check if a dropdown parameter was sent with value 'email'.

One solution was to use beforeValidate and setup selection statements, but I thought that would be better to have a validator that could just plug set some rules and if they are passed without errors, then the important one was executed.

I have created a GitHub repository for those willing to contribute on any of the extensions I created. Please, check the link at the bottom of this wiki.


Download and extract on protected/components/validators (for the sake of the following example). For the sake of the example I am going to use one of the issues a fellow Yii'er had and requested this extension to help him out.

From its post and only the first and easiest requirement, for more advance example, please look at the post:

  • province is required only if country has value = 86
public function rules(){
   return array(
             'province', 'application.components.validators.EConditionalValidator',
             'conditionalRules' => array('country', 'compare', 'compareValue' => 86),
             'rule' => array('required')

For enhancements, bug reports, etc. Please use the Forum Post

Change Log

  • version 1.0.1 Initial public release
  • version 1.0.2 Fixed bug for multiple rules (thanks ToolMayNARD)


web development has never been so fun

9 0
Yii Version: 1.1
License: BSD-2-Clause
Category: Validation
Developed by: Antonio Ramirez
Created on: Nov 3, 2011
Last updated: 6 years ago


show all

Related Extensions