ZF-3120: Zend_Form::_sort() can't sort when ordered and unordered elements are set (with solution)
Description
Get following code:
$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:
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.
Solution:
2507: while (array_search($index, $this->_order, true)) {
Comments
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.