We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Validators with empty values

I'm currently working on a project that relies heavily on the form builder, there's a customer profile form that has all information required on a customer. There's a contact number and email field that do NOT have the PresenceOf validator and therefore are not required fields however, the validators seem to validate even an empty value so Phalcon\Validation\Validator\Email will say a blank field isn't a valid email...

Anyway to change this without creating my own validators replicating the behaviour just not with empty fields?



13.4k
Accepted
answer

I've just looked at the source of Phalcon 2.0 and can see that there is an option "allowEmpty" which is what I was after. Shame it isn't documented anywhere!

https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/validation/validator/email.zep#L51