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

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

Closed
JaapMoolenaar opened this issue Feb 7, 2014 · 2 comments
Assignees
Milestone

Comments

@JaapMoolenaar
Copy link

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
Copy link
Contributor

@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
Copy link
Author

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
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
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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants