[NFR] Skip other validators if field is empty and optional
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.
+1
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
When will this be fixed? This behaviour makes phalcon forms almost unusable. Optional elements should only be validated if required and not empty.
Is this fixed yet?
I was struggling with this until I've found #1675 and #482.
Basically, all of the phalcon validation is useless without this simple feature.
@crocodile2u This simple feature is implemented in Phalcon 2
Wow, that's really-really nice to hear! Thanks for your work!
@andresgutierrez Implemented in 2.0.