ZF-3120: Zend_Form::_sort() can't sort when ordered and unordered elements are set (with solution)

Issue Type: Bug Created: 2008-04-16T10:21:15.000+0000 Last Updated: 2008-05-05T11:44:43.000+0000 Status: Resolved Fix version(s): - 1.5.2 (15/May/08)

Reporter: Ji?í Tomek (katulus) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments:


Get following code:

<pre class="highlight">
$form = new Zend_Form();
$form->addElement(new Zend_Form_Element_Submit('a',array('label'=>'a')));
$form->addElement(new Zend_Form_Element_Submit('b',array('label'=>'b', 'order'=>0)));
$form->addElement(new Zend_Form_Element_Submit('c',array('label'=>'c', 'order'=>1)));
echo $form;

Only submits 'b' and 'c' are displayed.

Reason: In Zend/Form.php (@version $Id: Form.php 8996 2008-03-22 16:59:06Z matthew $) there is:

<pre class="highlight">
2507:  if (array_search($index, $this->_order, true)) {
2508:      ++$index;
2509:  }
2510:  $items[$index] = $key;

In example above, this condition is true for index equal to 0 AND 1, but because there is just if, it is executed only once, so index is set to 1. To $items[1] is set submit 'a'. But it is overwritten by submit 'c', because submit 'c' has order set explicitly so no check is performed.


<pre class="highlight">
2507:  while (array_search($index, $this->_order, true)) {


Posted by Wil Sinclair (wil) on 2008-04-18T13:16:14.000+0000

Please evaluate and categorize as necessary.

Posted by Matthew Weier O'Phinney (matthew) on 2008-04-22T10:46:16.000+0000

Scheduling for next mini release.

Posted by Matthew Weier O'Phinney (matthew) on 2008-04-25T11:55:34.000+0000

Fix applied (with tests) in trunk and 1.5 release branch as of r9318.

Have you found an issue?

See the Overview section for more details.


© 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.