cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[NFR] Skip other validators if field is empty and optional

Open iforp opened this issue 13 years ago • 9 comments

If field is empty and 'required' validator is absent then other validators should be skipped. This is a very common scenario: the field must either be empty or have a valid format.

use Phalcon\Validation\Validator\PresenceOf,
    Phalcon\Validation\Validator\Email;

$validation = new Phalcon\Validation;
$validation->add('email_1', new Email);
$validation->add('email_2', new Email);
$validation->add('email_2', new PresenceOf);

// The validation should be passed if email_1 field is empty 'cause it optional

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

iforp avatar Jun 06 '13 05:06 iforp

+1

jeffreycahyono avatar Jun 13 '13 07:06 jeffreycahyono

Maybe this behavior should also be applied to Phalcon\Mvc\Model\Validator's If field value is null and the database allows to store nulls, then other validators should be skipped.

At least every validator should take the optional parameter that allow you to pass null instead of validation

iforp avatar Aug 23 '13 12:08 iforp

When will this be fixed? This behaviour makes phalcon forms almost unusable. Optional elements should only be validated if required and not empty.

mdietrich avatar Oct 08 '13 16:10 mdietrich

Is this fixed yet?

ranquild avatar Oct 03 '14 05:10 ranquild

I was struggling with this until I've found #1675 and #482.

lfbittencourt avatar Dec 30 '14 18:12 lfbittencourt

Basically, all of the phalcon validation is useless without this simple feature.

crocodile2u avatar Jan 06 '15 21:01 crocodile2u

@crocodile2u This simple feature is implemented in Phalcon 2

ghost avatar Jan 06 '15 21:01 ghost

Wow, that's really-really nice to hear! Thanks for your work!

crocodile2u avatar Jan 06 '15 21:01 crocodile2u

@andresgutierrez Implemented in 2.0.

Green-Cat avatar May 25 '15 22:05 Green-Cat