Issue

ZF2-413: Zend\Form\Element missing isArray support

Issue Type: Bug Created: 2012-07-20T12:37:03.000+0000 Last Updated: 2012-08-18T09:29:16.000+0000 Status: Resolved Fix version(s): Reporter: Raymond (rkolbe) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend\Form

  • Zend\Validator

Related issues: Attachments:

Description

It appears support for validating multicheckboxes (or any multi*) using the InArray has been removed. This existed in ZF1 (http://zend-framework-community.634137.n4.nabble.com/… and http://framework.zend.com/svn/framework/… (see $_isArray;

When trying to use a multicheckbox and the InArray validator in ZF2 (beta5) the validator is passed the whole array, is compared against string values in haystack, and thus never validates.

Here is the form and filter objects that can be used to reproduce this issue:

<pre class="highlight">
<?php
 
namespace Application\Form;
 
use Zend\Form\Form;
 
class Course extends Form
{
    public function __construct($name = null)
    {
        parent::__construct($name);
       
        $this->add(array(
            'name' => 'offerings',
            'options' => array(
                'label' => 'Offered'
            ),
            'attributes' => array(
                'options' => array(
                    'Online'    => 'offered_online',
                    'Classroom' => 'offered_in_classroom'
                )
            )
        ));
    }
}



<pre class="highlight">
<?php

namespace Application\Form;
 
use Zend\InputFilter\InputFilter;
use Zend\Validator;
 
class CourseFilter extends InputFilter
{
    public function __construct()
    {
        $this->add(array(
            'name'       => 'offerings',
            'required'   => true,
            'validators' => array(
                array(
                    'name'                => 'InArray',
                    'breakChainOnFailure' => true,
                    'options'             => array(
                        'haystack' => array('offered_in_classroom', 'offered_online'),
                        'messages' => array(
                            Validator\InArray::NOT_IN_ARRAY => 'Invalid option supplied for offering.'
                        )
                    )
                )
            )
        ));
    }
}

Comments

Posted by Chris Martin (cgmartin) on 2012-08-07T18:41:34.000+0000

Added functionality to the Explode Validator for validating each checked value against the haystack. See updated Zend\Form\Element\MultiCheckbox:

https://github.com/zendframework/zf2/…

Posted by Chris Martin (cgmartin) on 2012-08-07T22:22:52.000+0000

Also related... Created a Pull Request for a fix to the Select element, when it's "multiple" attribute is true:

https://github.com/zendframework/zf2/pull/2126

Posted by Maks 3w (maks3w) on 2012-08-18T09:29:16.000+0000

Patch merged

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts