views:

205

answers:

2

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.

A: 

If, all you are asking, is if the label tag is valid xhtml strict. You can run the HTML through a validator. Doing a google search I came up with this website that talks about the label tags in XHTML Strict standards. Worth a read, but I believe it is valid XHTML Strict.

But if you want to validate it W3C Validator Tool and see if it is allowed / throws validation errors.

If you are looking to remove it this SO Topic may help you.

Brad F Jacobs
A: 

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);
}
...
?>
manyxcxi