Issues

ZF-5033: Zend_Form_Element_Multi HTML validation warning

Description

When using form elements that are descendants of Zend_Form_Element_Multi you'll get HTML validation warnings because the label will point to a non-existent ID:

Example warning message: {quote}Line 116, Column 16: reference to non-existent ID "FACILITIES". {{

Interior facilities:}} {quote}

My suggestion is to drop generating a {{}} tag for such elements or at least don't give it the {{for}} attribute. Should be a pretty easy fix.

Comments

Actually, it's a non-trivial fix, as the Label decorator proxies to the FormLabel view helper - which requires an element name as its first argument. We may be able to pass a flag indicating that the "for" should not be rendered, however.

Which specific multi elements does this apply to? I'm fairly certain that Select and MultiSelect work properly...

I only checked using MultiCheckbox, but I assumed that the other Multi descendants were affected by this as well seeing as MultiCheckbox doesn't have any code that specifically deals with the label.

Well, MultiCheckbox and Radio both operate differently than other Multi elements, as they generate labels per input. I think we can put the flag only in the Radio class (from which MultiCheckbox inherits), and work from there.

Are you still working on this?

Invalid HTML Code isn't very nice if you want to put a "W3C Valid HTML" button on your page ;-)

Current trunk validates fine with


$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());