Issue with ValidateOptions Methods

Issue with ValidateOptions Methods

ayzayz Posts: 63Questions: 23Answers: 1

In PHP validation, why are ->allowEmpty and ->optional not validation methods on their own? To my mind, making them methods to ValidateOptions is somewhat akin to an unnormalized database. Eg why should I be able to allowEmpty under Validate::minLen as well as under Validate::maxLen for the very same field? It just seems clumsy; or is there something Iā€™m overlooking?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer āœ“

    The validation requires that all validation logic passes - i.e. if you assign two validators, then they must both pass. There isn't currently the ability to shortcut the logic for the validators which allowEmpty would require. We might also potentially run into the issue with ordering of chained validators if that were allowed (having allowEmpty as the final one in the chain would be pointless for example).

    I absolutely take your point though and that is why there are combination validators such as minMaxLen for the example you give, meaning that it would only need to be entered once (although the error message would need to be more generic).

    This is certainly something for me to consider as we move forward - thanks for the feedback!

    Allan

This discussion has been closed.