0

我正在将 zend 表单设置为:

class Application_Form_Ticket_Search extends Zend_Form
{
    private $_itemList;

    public function setItemList($itemList)
    {
        $this->_itemList[0] = 'Select Item';      // Default selected value
        foreach($itemList AS $key => $value)
        {
            $this->_itemList[$value['REFERENCE']] = $value['DESCRIPTION'];
        }
    }

    // Initializes search form
    public function init()
    {           
        // Settings POST type request
        $this->setName('search')->setMethod('GET');        

        $this->addElement('select', 'item',
                array(  'label'     =>    'Item',
                        'filters'   =>    array('StringTrim'),
                        'multiOptions' => $this->_itemList
        ))->removeDecorator('HtmlTag');

        $this->addElement('submit', 'search',
                array(  'class'     =>    'btn btn-primary btn-small',
                        'label'     =>    'Search',
                        'style'     =>    'margin-left:70px;')
        )->removeDecorator('HtmlTag');        
    }    
}

并在控制器中传递表单的选择框列表为:

$searchForm = new Application_Form_Ticket_Search(array('itemList' => $itemList));

并填充值(在发出搜索请求后),例如:

$searchForm->populate($filters);

当我调试$filters数组时,输出是:

array(1) { ["item"]=> string(36) "201031999999992010051000000170430719" } 

现在问题出在 HTML 上:我收到了一个输出(当在下拉列表中选择了一个值时):

<select name="item" id="item">
<option value="0" label="Select Item">Select Item</option>
<option value="201031999999992010051000000170430719" label="ELITE FRT CHWG N/AV GUM ST 15CT" selected="selected">ELITE FRT CHWG N/AV GUM ST 15CT</option>
<option value="201031999999992010051000000170430869" label="Consolidator" selected="selected">Consolidator</option>
<option value="201031999999992010051100000170450719" label="DAVID PUMPKIN SEEDS" selected="selected">DAVID PUMPKIN SEEDS</option>
<option value="201031999999992010051100000170450739" label="Consolidator" selected="selected">Consolidator</option>
<option value="201031999999992010051000000170430809" label="GARDETTO ORIGINAL" selected="selected">GARDETTO ORIGINAL</option>

现在您可以看到在下拉列表中选择了每个值,并且我总是得到最后选择的值。我做错了什么或者可以为此做些什么?

4

1 回答 1

0

尝试:

class Application_Form_Ticket_Search extends Zend_Form
{
    public function setItemList($itemList)
    {
        $items = array('Select Item');      
        foreach($itemList as $key => $value) {
            $items[$value['REFERENCE']] = $value['DESCRIPTION'];
        }
        $this->getElement('item')->setMultiOptions($items);
    }

    // Initializes search form
    public function init()
    {           
        // Settings POST type request
        $this->setName('search')->setMethod('GET');        

        $this->addElement('select', 'item',
                array(  'label'     =>    'Item',
                        'filters'   =>    array('StringTrim')
        ))->removeDecorator('HtmlTag');

        $this->addElement('submit', 'search',
                array(  'class'     =>    'btn btn-primary btn-small',
                        'label'     =>    'Search',
                        'style'     =>    'margin-left:70px;')
        )->removeDecorator('HtmlTag');        
    }    
}

$searchForm = new Application_Form_Ticket_Search();
$searchForm->setItemList(array('itemList' => $itemList));
于 2012-04-10T16:24:42.843 回答