Zend Framework

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

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.5.1
  • Fix Version/s: 1.5.2
  • Component/s: Zend_Form
  • Labels:
    None
  • Fix Version Priority:
    Must Have

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)) {

Activity

Hide
Wil Sinclair added a comment -

Please evaluate and categorize as necessary.

Show
Wil Sinclair added a comment - Please evaluate and categorize as necessary.
Hide
Matthew Weier O'Phinney added a comment -

Scheduling for next mini release.

Show
Matthew Weier O'Phinney added a comment - Scheduling for next mini release.
Hide
Matthew Weier O'Phinney added a comment -

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

Show
Matthew Weier O'Phinney added a comment - Fix applied (with tests) in trunk and 1.5 release branch as of r9318.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
30m
Original Estimate - 30 minutes
Remaining:
30m
Remaining Estimate - 30 minutes
Logged:
Not Specified
Time Spent - Not Specified