Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Fix identical validator#3803

Closed
iquabius wants to merge 2 commits into
zendframework:masterfrom
iquabius:fix-identical-validator
Closed

Fix identical validator#3803
iquabius wants to merge 2 commits into
zendframework:masterfrom
iquabius:fix-identical-validator

Conversation

@iquabius
Copy link
Copy Markdown
Contributor

These changes adds the possibility to use Zend\Validator\Identical to validate a form input that lives inside a fieldset:

See exemple below:

use Zend\Form\Element;
use Zend\Form\Fieldset;
use Zend\Form\Form;
use Zend\InputFilter\Input;
use Zend\InputFilter\InputFilter;

$user = new Fieldset('user'); // (1)
$user->add(array(
    'name' => 'email', // (2)
    'type' => 'Zend\Form\Element\Email',
    'attributes' => array(
        'required' => 'required',
    ),
    'options' => array(
        'label' => 'Email',
    ),
));

$signUp = new Form('signUp');
$signUp->add($user);
$signUp->add(array(
    'name' => 'confirmEmail', // (3)
    'type', 'Zend\Form\Element\Email',
    'options' => array(
        'label' => 'Confirm your email',
    ),
));

$inputFilter = new InputFilter();
$inputFilter->add(array(
    'name' => 'confirmEmail', // references (3)
    'required' => true,
    'validators' => array(
        array(
            'name' => 'Identical',
            'options' => array(
                // 'user' references 'user' fieldset (1), and 'email'
                // references 'email' element inside 'user' fieldset (2)
                'token' => array('user' => 'email'),
            ),
        ),
    ),
));

$signUp->setInputFilter($inputFilter);

$signUp->setData(array(
    'user' => array(
        'email' => '[email protected]',
    ),
    'confirmEmail' => '[email protected]',
));

// Will return true because "user['email']" == "confirmEmail"
if ($signUp->isValid()) {
}

@ghost ghost assigned weierophinney Feb 19, 2013
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a backwards incompatible change; test for array inside the method instead.

weierophinney added a commit that referenced this pull request Feb 19, 2013
- Removed "array" typehint from $context; added check within method body
weierophinney added a commit that referenced this pull request Feb 19, 2013
@weierophinney
Copy link
Copy Markdown
Member

I fixed the BC-breaking issue when merging.

@iquabius
Copy link
Copy Markdown
Contributor Author

I don't see the diference besides the exeption instead of the native php error, there's some other reason I'm not seeing!?

weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
- Removed "array" typehint from $context; added check within method body
weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants