Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
Satsume opened this Issue · 2 comments

3 participants

@Satsume

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
Closed

Fixes #5796 #5808

@samsonasik

@Satsume I created PR #5808 to fix it

@samsonasik samsonasik referenced this issue from a commit in samsonasik/zf2
@samsonasik samsonasik added unit test for #5796 72f4d9e
@samsonasik samsonasik referenced this issue from a commit in samsonasik/zf2
@samsonasik samsonasik added unit test for #5796 c59506b
@Satsume

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
@Ocramius Ocramius self-assigned this
@weierophinney weierophinney closed this issue from a commit
@samsonasik samsonasik Fixes #5796 14851cb
@weierophinney weierophinney referenced this issue from a commit
@weierophinney weierophinney [#5808] Fixed test case
to test the specific behavior as reported in #5796. Test now fails before the
patch, passes afterwards.
e2d15cf
@gianarb gianarb referenced this issue from a commit in zendframework/zend-validator
@samsonasik samsonasik Fixes zendframework/zf2#5796 6c9f00b
@gianarb gianarb referenced this issue from a commit in zendframework/zend-validator
@samsonasik samsonasik added unit test for zendframework/zf2#5796 8ba7e60
@weierophinney weierophinney referenced this issue from a commit in zendframework/zend-validator
@weierophinney weierophinney Merge pull request zendframework/zf2#5808 from samsonasik/fix/multipl…
…e-invalid-explodevalidator

Fixes zendframework/zf2#5796
a446e88
@weierophinney weierophinney referenced this issue from a commit in zendframework/zend-validator
@weierophinney weierophinney [zendframework/zf2#5808] Fixed test case
to test the specific behavior as reported in zendframework/zf2#5796. Test now fails before the
patch, passes afterwards.
23c1f01
@weierophinney weierophinney referenced this issue from a commit in zendframework/zend-validator
@weierophinney weierophinney Merge branch 'hotfix/5808' ee0e7b9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.