开发者

option tags created from Zend_Form_Element_Select wrong

I'm using the Zend_Form_Element_Select to create my select list, but when I view the source, the options tags look like this:

<select name="things" id="things">
    <option value="thing1" label="Thing 1">Thing 1</option>
    <option value="thing2" label="Thing 2">Thing 2</option>
    <option value="thing3" label="Thing 3">Thing 3</option>
</select>

the label attribute doesn't need to be in there. It has no use being in there. The value should match what's in label. Here's the code I used:

$things = new Zend_Form_Element_Select('things');
$things->setLabel('Things:');
$things->setRequired(TRUE);
$things->addMultiOptions(array(
    'thing1'=>'Thing 1',
    'thing2'=>'Thing 2',
    'thing3'=>'Thing 3'
));
$this-&开发者_StackOverflowgt;addElement($things);

Am I going about this all wrong or is this just the way Zend works and I just have to deal with it?


The array you pass in takes the form value=>label, so you would want to do

$things->addMultiOptions(array(
  'Thing 1'=>'Thing 1',
  'Thing 2'=>'Thing 2',
  'Thing 3'=>'Thing 3'
));


Attribute label "specifies a shorter label for an option" and it is a valid attribute of an option tag. So because all your options are different, the labels will also be different.


maybe if you remove first?

->removeDecorator('Label')
                                    ->removeDecorator('HtmlTag');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜