atleastvalidator Validate at least one from attributes

  1. Usage
  2. Installation
  3. Resources

If you need user to fill in at least one from a pre-defined group of form fields AtLeastValidator is the right tool for you

Usage

As usual you create the rules for checking individual parameters and at the end you add a rule for all attributes with AtLeastValidator validator.

For example you want a user to fill in email OR telephone, so you define following individual attributes:

public function rules()
{
    return array(
        array('phone', 'required'),
        array('email', 'email', 'allowEmpty' => false),
    );
}

And then you add a rule for AtLeastValidator:

public function rules()
{
    return array(
        array('phone', 'required'),
        array('email', 'email', 'allowEmpty' => false),
        array('email, phone', 'ext.atLeastValidator'),
    );
}

Now if a user enters email OR phone you model will becomes valid.

Installation

Put the AtLeastValidator.php file under the extensions/ subdirectory of application base directory.

Resources

1 2
7 followers
711 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Validation
Tags: validator
Developed by: vol0da
Created on: Oct 28, 2011
Last updated: 12 years ago

Downloads

show all

Related Extensions