ZF-3024: Zend_Form Radio and MultiCheckbox elements fail W3C validations due to missing IDs

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.

Potential solutions:

  • Do not use an id with the label in these situations (may be invalid markup)
  • Generate a unique ID for each input element, and utilize the first for the label.


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')));

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.