0

我有一个表单,我正在尝试添加一个简单的选择元素以使用以下 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');

它可以很好地呈现到页面,但是它正在生成以下 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>

为什么要..label="..."<option>标签中添加a?这实际上是 XHTML 标准应该如何做的吗?我的 doctype 设置为 XHTML Strict。

4

2 回答 2

0

如果,您要问的是,标签标签是否有效 xhtml 严格。您可以通过验证器运行 HTML。做一个谷歌搜索我想出了这个网站,它讨论了 XHTML Strict 标准中的标签标签。值得一读,但我相信它是有效的 XHTML Strict。

但是如果你想验证它W3C Validator Tool并查看它是否被允许/抛出验证错误。

如果您想删除它,这个 SO 主题可能会对您有所帮助。

于 2010-08-06T19:55:46.383 回答
0

可以有选择地删除额外的标签。我在下面给出了一个示例,它删除了隐藏元素的所有不必要的装饰器:

<?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);
}
...
?>
于 2010-09-10T20:49:42.443 回答