dpwdsmbvm496180204 2010-08-06 19:26
浏览 62
已采纳

Zend框架:Zend表单选择使用MultiOptions生成详细HTML

I have a form that I am trying to add a simple select element to using the following php:

$dateFormat = new Zend_Form_Element_Select('dateFormat');
        $dateFormat->setLabel('Date Format:');
        $dateFormat->setRequired(true)->addValidator('NotEmpty');
        $dateFormat->addMultiOptions(array(
            'MM/dd/yyyy' => "US Standard         - MM/dd/yyyy",
            'dd/MM/yyyy' => "Int'l Standard      - dd/MM/yyyy",
            'MM-dd-yyyy' => "US Standard Dash    - MM/dd/yyyy",
            'dd-MM-yyyy' => "Int'l Standard Dash - dd/MM/yyyy",
        ));
        $this->addElement($dateFormat,'dateFormat');

It renders to the page just fine, however it is generating the following XML:

<dt id="dateFormat-label"><label for="dateFormat" class="required">Date Format:</label></dt>
<dd id="dateFormat-element">
<select name="dateFormat" id="dateFormat">
    <option value="MM/dd/yyyy" label="US Standard         - MM/dd/yyyy">US Standard         - MM/dd/yyyy</option>
    <option value="dd/MM/yyyy" label="Int'l Standard      - dd/MM/yyyy">Int'l Standard      - dd/MM/yyyy</option>
    <option value="MM-dd-yyyy" label="US Standard Dash    - MM/dd/yyyy">US Standard Dash    - MM/dd/yyyy</option>

    <option value="dd-MM-yyyy" label="Int'l Standard Dash - dd/MM/yyyy">Int'l Standard Dash - dd/MM/yyyy</option>
</select></dd>

Why is it putting a ..label="..." in the <option> tag? Is this actually how it is supposed to be done for XHTML standards? I have my doctype set to XHTML Strict.

  • 写回答

2条回答 默认 最新

  • dongwei2882 2010-09-10 20:49
    关注

    The extra tags can be removed selectively. I've given an example below that removes all the unnecessary decorators for a hidden element:

    <?php
    ...
    public function init()
    {
    ...
    
     $this->addElement(new Zend_Form_Element_Hidden('configId'));
            $cid = $this->getElement('configId');
            $cid->removeDecorator('DtDdWrapper');
            $cid->removeDecorator('HtmlTag');
            $cid->removeDecorator('Label');
            $cid->setRequired(true);
    }
    ...
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了