Issue Type: Sub-task Created: 2008-04-02T10:44:26.000+0000 Last Updated: 2010-04-05T07:43:31.000+0000 Status: Closed Fix version(s): Reporter: Matthew Weier O'Phinney (matthew) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form
Related issues: - ZF-2937
Attachments: - FormRadio.patch
Multi elements such as Radio and MultiCheckbox do not pass W3C validations with the default decorators due to an issue with how labels are generated.
W3C says that the 'for' attribute of an element must point to the id of a single other input element in the form. However, in cases such as the radio and multicheckbox, there are actually multiple elements in the form related to the same label. Our current solution uses the element name (which is the same between all input elements) in the label "for" attribute -- which is invalid markup.
Posted by Matthew Weier O'Phinney (matthew) on 2008-04-22T11:55:53.000+0000
Scheduling for next minor release.
Posted by Andrew Collington (amnuts) on 2009-01-13T03:18:23.000+0000
Doesn't seem that the solution to this was put in to a minor release since Matthew's comment in April, as looking at version 1.7.2 now the problem of having no 'for' attribute in the labels still exists. Random IDs are generated, but then only used within the input tag itself.
I'd suggest simply updating FormRadio.php so that the line:
$radio = '<label'
$radio = '<label for="' . $optId . '"'
Posted by Andrew Collington (amnuts) on 2009-01-22T03:29:13.000+0000
Patch file for the update.
Posted by Matthew Weier O'Phinney (matthew) on 2009-10-15T08:15:53.000+0000
This has been resolved at some point in the past; please see Zend_View_Helper_FormRadioTest::testRadioLabelContainsForAttributeTag(), as well as line 161 of the FormRadio view helper, which reads:
<pre class="highlight"> . $this->_htmlAttribs($label_attribs) . ' for="' . $optId . '">'
Posted by Edouard Cunibil (duael) on 2010-02-10T03:43:08.000+0000
I found a solution by redefining "Label" decorator on these fields !
You have to pass the "disableFor" option to the decorator. It will remove the "for" attribute of the main "label" tag but not from the checkboxes' ones.
Posted by Christian Albrecht (alab) on 2010-04-05T07:07:34.000+0000
Current trunk validates fine with
<pre class="highlight"> $form = new Zend_Form(); $form->addElement('Radio', 'Woo', array('MultiOptions' => array('foo','bar','baz'))); $form->addElement('Select', 'Zaa', array('MultiOptions' => array('foo','bar','baz'))); $form->addElement('Multiselect', 'Qua', array('MultiOptions' => array('foo','bar','baz'))); $form->addElement('MultiCheckbox', 'Qui', array('MultiOptions' => array('foo','bar','baz'))); $form->addElement('submit','submit'); die($form->render());
Have you found an issue?
See the Overview section for more details.