Zend Framework

Add 'negate' option to validators

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Won't Fix
  • Affects Version/s: 1.9.5
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Validate
  • Labels:
    None

Description

When adding a validator to a form, it seems impossible to use the opposite of a validator.

Use Case: Having a form validator that does check if some value does not occur in an array. Want to use the 'not' InArray validator. Zend_Form will call isValid() and we can't use the opposite value of the boolean.

Adriaan Graas

Activity

Hide
Thomas Weidner added a comment -

This is not possible with a generic solution.

The problem is, that when something is "valid" it does not mean that it can simply be made "not valid". See Regex for example: Just because a regex returns true, it is not said that it also works the other way.

Or take an CreditCard number. The check if a credit card is valid uses multiple validations. They are run part by part and only the sum of all checks gives the result.

On the other side, what should be returned when a validation is true (false). This would negotate the complete message logic.

I see such a behaviour problematic.

Show
Thomas Weidner added a comment - This is not possible with a generic solution. The problem is, that when something is "valid" it does not mean that it can simply be made "not valid". See Regex for example: Just because a regex returns true, it is not said that it also works the other way. Or take an CreditCard number. The check if a credit card is valid uses multiple validations. They are run part by part and only the sum of all checks gives the result. On the other side, what should be returned when a validation is true (false). This would negotate the complete message logic. I see such a behaviour problematic.
Hide
Adriaan Graas added a comment -

Thanks for your reply.

Why not just invert the most final resulting validation. It's the same as inverting the result of isValid(). It might be possible to implement this in Zend_From instead of in the validators, maybe that makes more sense. It makes sense (though it would be quite uncommon) to check if an given number is 'not' a creditcard number. I don't see a validator chain messing that up.

I can see the message logic going haywire with this though: messages tell something over the validity of input, while they would now need to tell something about the invalidity of the input. I indeed don't see a solution for this straightaway.

Show
Adriaan Graas added a comment - Thanks for your reply. Why not just invert the most final resulting validation. It's the same as inverting the result of isValid(). It might be possible to implement this in Zend_From instead of in the validators, maybe that makes more sense. It makes sense (though it would be quite uncommon) to check if an given number is 'not' a creditcard number. I don't see a validator chain messing that up. I can see the message logic going haywire with this though: messages tell something over the validity of input, while they would now need to tell something about the invalidity of the input. I indeed don't see a solution for this straightaway.
Hide
Thomas Weidner added a comment -

Closing as won't fix

If someone is in need of an reversed validator he should extend the validator, reverse the output and change the messages according to his needs.

Show
Thomas Weidner added a comment - Closing as won't fix If someone is in need of an reversed validator he should extend the validator, reverse the output and change the messages according to his needs.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: