views:

123

answers:

2

I would like to add an attribute to some form elements in the action controller, I can do it like this:

$form->element_name->setAttrib('description', '<a href="/controller/action">Anchor</a>');

However in the above example the second argument gets escaped. I would like to have it unescaped. How can I do that?

+1  A: 

You may have to experiment a bit but typically

$element->setAttrib("escape", false);

should work. I'm using it to not escape the content in a Zend_Form_Element_MultiCheckbox subclass right now. There's a setEscape method in the Decorator abstract that I believe this flags but the documentation isn't clear (as made obvious by the "enhancement" request).

Typeoneerror
+1  A: 

You can use $decorator->setEscape(false); on Description decorator. Retieve it like $descriptionDEcorator = $element->getDecorator('Description');

Tomáš Fejfar
I set that on the decorator, the problem is that it still gets escaped if I set the description in the controller. In the form file it works but the description changes depending on request parameters so I have to set it in the controller.
Richard Knop
I'd suggest checking if you're not altering decorators anywhere else then form's init() method. This looks like you set escaping and then somewhere set different set of decorators.
Tomáš Fejfar
This works 100%.
Tomáš Fejfar