ZF-3924: isValid() throws exception with deeply nested subforms

Issue Type: Bug Created: 2008-08-11T09:24:42.000+0000 Last Updated: 2010-03-31T09:51:15.000+0000 Status: Resolved Fix version(s): Reporter: Jason Eisenmenger (jasoneisen) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: - ZF-9348



<pre class="highlight">
    public function testAction()
       $subForm1 = new Zend_Form_Subform(array('legend'=>'Subform 1'));
       $subForm2 = new Zend_Form_Subform(array('legend'=>'Subform 2'));
       $subForm3 = new Zend_Form_Subform(array('legend'=>'Subform 3'));
       $subForm3->addElement('checkbox', '1', array('label' => 'Checkbox'));
       $subForm3->addElement('text', '2', array('label' => 'Textbox'));
       $subForm2->addElement('checkbox', '1', array('label' => 'Checkbox'));
       $subForm2->addElement('text', '2', array('label' => 'Textbox'));
       $subForm2->addSubform($subForm3, '3');
       $subForm1->addSubForm($subForm2, '2');
       $form = new Zend_Form();
       $form->addSubform($subForm1, '1');
       $form->addElement('submit', 'submit', array('label' => 'Submit'));
       if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
            echo "Succeeded";
       $this->view->form = $form;

This throws the following exception:

<pre class="highlight">
exception 'Zend_Form_Exception' with message 'Zend_Form::Zend_Form::isValid expects an array' in /Users/Jason/Sites/asdf/library/Zend/Form.php:1973 Stack trace: 
#0 /Users/Jason/Sites/asdf/library/Zend/Form.php(1995): Zend_Form->isValid('') 
#1 /Users/Jason/Sites/asdf/library/Zend/Form.php(1993): Zend_Form->isValid(Array) 
#2 /Users/Jason/Sites/asdf/library/Zend/Form.php(1993): Zend_Form->isValid(Array) 
#3 /Users/Jason/Sites/asdf/application/modules/default/controllers/TestController.php(47): Zend_Form->isValid(Array)

Things to note:

1: This will work fine when the elements from subform 2 are removed 2: This will work fine when subform 3 is removed entirely 3: When all element names are unique and not the same name of any subform it works fine, but if you name the elements '1', '2', '3', and '4' respectively, subform 3 won't be displayed, and the form will still fail.


Posted by Bernd Matzner (bmatzner) on 2009-01-27T17:28:12.000+0000

The problem occurs when subform names are identical with element names, so it's probably good advice to always keep subform, display group, and element names unique in a form. It would be great if there was an exception that makes clear that unique names are required.

Posted by Christian Albrecht (alab) on 2010-03-05T21:54:20.000+0000

Had the same problem and found a fix for this, having equal names for a Child Element of a SubForm and the SubForm itself should work, imho.

Posted by Christian Albrecht (alab) on 2010-03-18T08:21:51.000+0000

Fixed in [ZF-9348]

Posted by Christian Albrecht (alab) on 2010-03-25T13:24:02.000+0000

Reopened because suggested fix is not reviewed and committed yet.

Posted by Christian Albrecht (alab) on 2010-03-31T09:51:14.000+0000

Matthew Weier O'Phinney resolved [ZF-9348] Patch applied to trunk and 1.10 release branch.

Have you found an issue?

See the Overview section for more details.


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

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