ZF-11744: Setting the same order on a FormElement "deletes" Elements

Issue Type: Bug Created: 2011-09-15T13:22:00.000+0000 Last Updated: 2011-09-20T14:26:17.000+0000 Status: Open Fix version(s): Reporter: Michiel Thalen (chielsen) Assignee: Christian Albrecht (alab) Tags: - Zend_Form

Related issues: Attachments:


When you have 2 or more elements with the same order:

<pre class="highlight">
$form->addElement(new Zend_Form_Element_Text('one', array('order' => 1)));
$form->addElement(new Zend_Form_Element_Text('two', array('order' => 1)));

The first element doesn't get show, because internally the sort function overwrites it. My solution is to alter the _sort method and let it check for duplicate Order values. If found, add a (couple) of thousands. This is a working solution for up to 1000 duplicate orderV values.

<pre class="highlight">
     * Sort items according to their order
     * @return void
    protected function _sort()
        if ($this->_orderUpdated) {
            $items = array();
            $index = $uniqOrder = 0 ;
            foreach ($this->_order as $key => $order) {
                if (null === $order) {
                    if (null === ($order = $this->{$key}->getOrder())) {
                        while (array_search($index, $this->_order, true)) {
                        $items[$index] = $key;
                    } else {
                        $items[$order] = $key;
                } else {
                    $items[isset($items[$order]) ? strval($order + (++$uniqOrder)/1000) : $order] = $key;

            $items = array_flip($items);
            $this->_order = $items;
            $this->_orderUpdated = false;

Btw why don't we have a proper coding system? I can put above code into code tags and we still don't have php!! syntax support.


Posted by Frank Br├╝ckner (frosch) on 2011-09-20T14:26:17.000+0000

Code tags added.

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.