Zend Form Element Label "for" Attribute

1.2k views Asked by At

I subclass Zend_Form to allow re-use as I describe in my other SO question. It's working very well, except for one issue that I found. In my view script I use this code to render the label for fields:

echo $this->formLabel($this->element->getFullyQualifiedName(),
        $this->element->getLabel());

The rendered label has the original element id as the value in the for attribute rather than the new, suffixed, element id. Is there a bug in the Zend code, am I missing a step or doing something incorrectly?

1

There are 1 answers

1
Marcin On BEST ANSWER

I think the reason is that you use formLabel view helper independently. As a result, the helper is not aware of any attributes that you specified for your input text field. So, you should provide these attributes to the formLabel. For example you could do the following:

echo $this->formLabel(
        $this->element->getFullyQualifiedName(),
        $this->element->getLabel(),
        $this->element->getAttribs() 
);

The above code should produce for tag that matches your input elements id. Otherwise, the for tag will be set to the elements name.