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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化