\Zend\Form\Element\Email, with multiple=true leads to “Array to string conversion” #5796

Closed
JaapMoolenaar opened this Issue Feb 7, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@JaapMoolenaar

PHP throws a notice when validating a Email FormElement with multiple set to true.

I set-up a form like below:

$form = new \Zend\Form\Form();

// Using a \Zend\Form\Element\Email with 'multiple' => true in the attributes:
// - Adds a \Zend\Validator\EmailAddress
// - And a \Zend\Validator\Explode
$form->add(
    array(
        'type' => 'Zend\Form\Element\Email',
        'name' => 'emails',
        'options' => array(
            'label' => 'E-mailaddresses',
        ),
        'attributes' => array(
            'multiple' => true,
        ),
    )
);

ZF2 automatically adds an e-mailaddress validator ( \Zend\Validator\EmailAddress ). And ( because I set 'multiple' => true in it's attributes ) an explode validator ( \Zend\Validator\Explode ), which should run the e-mailaddress validator for every value once exploded using the separator ( by default a ',' ), according to the manual that is.

The tests:

  • The validator works perfectly for multiple valid e-mailaddresses, I get no errors.
  • It also works perfectly for 1 invalid e-mailaddress ( with or without valid e-mailaddresses ).
  • However when submitting 2 ( or more ) invalid e-mailaddress I get a notice: "Notice: Array to string conversion in \vendor\zendframework\zendframework\library\Zend\Validator\AbstractValidator.php on line 159".

I recreated the bug in a separate module for the standard ZendSkeletonApplication.

( You can clone my tests from github here: git clone https://github.com/Satsume/ZendSkeletonApplication-Tests.git --recursive. Once installed go to /tests/ to see the form. )

@samsonasik samsonasik referenced this issue Feb 10, 2014

Closed

Fixes #5796 #5808

@samsonasik

This comment has been minimized.

Show comment
Hide comment
@samsonasik

samsonasik Feb 10, 2014

Contributor

@satsume I created PR #5808 to fix it

Contributor

samsonasik commented Feb 10, 2014

@satsume I created PR #5808 to fix it

samsonasik added a commit to samsonasik/zf2 that referenced this issue Feb 10, 2014

samsonasik added a commit to samsonasik/zf2 that referenced this issue Feb 10, 2014

@JaapMoolenaar

This comment has been minimized.

Show comment
Hide comment
@JaapMoolenaar

JaapMoolenaar Feb 10, 2014

Great! That was the fix I was thinking too, but I didn't want to sound overly smart ;-)

Great! That was the fix I was thinking too, but I didn't want to sound overly smart ;-)

@Ocramius Ocramius added this to the 2.2.6 milestone Mar 4, 2014

@Ocramius Ocramius self-assigned this Mar 4, 2014

weierophinney added a commit that referenced this issue Mar 4, 2014

[#5808] Fixed test case
to test the specific behavior as reported in #5796. Test now fails before the
patch, passes afterwards.

weierophinney added a commit that referenced this issue Mar 4, 2014

gianarb pushed a commit to zendframework/zend-validator that referenced this issue May 15, 2015

gianarb pushed a commit to zendframework/zend-validator that referenced this issue May 15, 2015

weierophinney added a commit to zendframework/zend-validator that referenced this issue May 15, 2015

weierophinney added a commit to zendframework/zend-validator that referenced this issue May 15, 2015

[zendframework/zendframework#5808] Fixed test case
to test the specific behavior as reported in zendframework/zendframework#5796. Test now fails before the
patch, passes afterwards.

weierophinney added a commit to zendframework/zend-validator that referenced this issue May 15, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment