Issues

ZF-7954: Add a collection of context sensitive validators

Description

It would be great to have a series of context sensitive validators.

Since the context isn't supported by regular validation chains, and used mainly by forms, maybe they should be under Zend_Form_Validate instead to reduce confusion, or does that just make it worse?

Some useful validators that would be great if they had context sensitive alternatives:

Db_RecordExists Db_NoRecordExists Between GreaterThan LessThan Identical NotEmpty Regex

Let me know if this should go through the proposal process instead.

Comments

No, this is nonsense.

Validators themself should not take care of context. Context is only a way of Zend_Form to prevent problems on actual API of Zend_Form.

What should a identical validator for example to with a context ? Identical means that token and value are 100% identical. A context would only be usefull when it has to check only a part, which means that it would then no longer be identical but only partitial. Same goes for other validators.

And we can not add context to the interface as this would mean that all validators can not be used standalone anymore, or have problems when you change Zend_Forms API or extend it with a own implementation.

Actually there is already a proposal which aims to solve this problem because context was added a few months ago to Zend_Form.

Closing as won't fix.

The existing proposal has another way to solve this problem, than extending all validators, or breaking the API. It will not create duplicate validators nor will it change existing validators.

I'm not proposing that all the validators be extended, as many of them don't make sense to validate against the context.

Here's an example of what a context sensitive Identical validator would look like (which would come in very handy with a registration form that asks you to enter the password twice):


$form->addElements(array(
    'password' => array(
        'type' => 'text',
        'options' => array(
            'label' => 'Password'
        )
    ),
    'password_confirm' => array(
        'type' => 'text',
        'options' => array(
            'label' => 'Password Confirm',
            'validators' => array(
                array('Identical', true, array('%password%'))
            )
        )
    )
));

In this case, the token %password% gets replaced with the value from the password value in the context.

But as you say, there's a proposal that is supposed to fix all this. Could you provide a link to the proposal? I know Matthew is working on refactoring Zend_Form, but his proposal hasn't been updated in a year and a half, and the other proposals are much older.

Sorry, had a brain fart. Was looking for Zend_Form related proposals, not Zend_Validate. I'm assuming you're referring to Zend_Validate/Filter_Builder? (http://framework.zend.com/wiki/display/…) It does solve some issues, but would need to be supported by Zend_Form to make it applicable.