Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

vol0da/yii-extension-atleastvalidator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Description

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.

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:

<?php

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

?>

And then you add a rule for AtLeastValidator:

<?php

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.

Usage

At least one of attributes attribute1, attribute2, attribute3 must be filled by an user.

<?php

public function rules()
{
    return array(
        array('attribute1, attribute2, attribute3', 'required'),
        array('attribute1, attribute2, attribute3', 'ext.atLeastValidator'),
    );
}

?>

An user must fill at least phone or valid email.

<?php

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

?>

About

AtLeastValidator extension for Yii framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages