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 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊