Adding a link to a form element with Zend Framework
At work, I am at the moment working on a Zend Framework project. Opposite to earlier projects with Zend Framework, I am slowly learning of the power behind the framework. But not all of the power is document well enough. On friday, I encountered one such small detail.
The problem I was stumped on friday was stupid enough. We have a form builder using Zend_Form that builds a form based on external XML input. In certain situations, a form field needs to have an associated link with it.
I was quickly told by the friendly people in #php_bnl on irc.freenode.net that I needed to use Decorators for that, so I went diving into the documentation. Reading the official documentation, I couldn't really get into how exactly the decorators worked and what I could do with them, however, DevZone to the rescue, because Matthew wrote an excellent article there on using the Decorators with Zend_Form. After reading through this article, I quickly understood how things worked, and had easily solved my problem. Well, almost.
I got as far as setting the decorator order using $element->setDecorators(array()), and then, since I was using the Description decorator for this purpose, using $element->setDescription() to add my link to the form. All seemed well, except for one thing: Instead of a link being added to the form, I got the escaped HTML output.
Diving back into the documentation, I really couldn't figure out how to solve this. I knew there should be an easy way to do it, but I couldn't figure it out. on IRC, I mostly got suggestions telling me to extend the element class I was trying to add a link to, but that seemed overkill for such a small exception. I tweeted my frustration, and quickly got a response from Matthew that I should e-mail him.
It seems I was indeed very close and there is indeed a very simple solution to the problem: you need to set the decorator with an additional configuration parameter. So, this will work:
$element->setDecorators(array(array('Description', array('escape' => false))));
Of course a note needs to be put here: Don't use this easily. You *are* turning off the escaping, so you need to be sure that whatever you put into the description is save data. But, being the slightly pragmatic developer that I am, for a situation like this, I much prefer this approach over having to subclass an element and override quite a few of the original methods of the element.
August 10, 2008 - tags: zend, zend framework, Zend_Form, php, decorators
Comments
felixdv: Glad you found out a way to make it work! You see, Zend framework has a solution for (nearly) everything
Ivo: I'm always slightly amazed at questions like this, and especially the 'frustration' that people seem to get from it.
Had you fired up a step-debugger, wouldn't you have found about the escaping bit in, like, 10 minutes? Surely the code that does the escaping can't be far from your call, and possibly the fact that it checked for this 'escape' paramater would've been clear from the code.
I guess I'm always sort of amazed by the fact that when it comes to frameworks or libraries, people just stop at the api border and don't dare to look into the code.

Gailin: Most people don't want to go behind the curtain of the API, because they use an API, in theory, to save time. The need to go behind the curtain generally arises when the API is not properly documented, as in the example above.
If you had to dig under the surface of most APIs or libraries you used, then I would hazard a guess that those API would not be used nearly as much.
Duo: Stefan,
I used your example for a checkbox element's label however this caused the checkbox to not appear. Simple adjustment, but I've posted my solution here: http://ireallylikesushi.com/blog/2009/07/23/adding-html-to-a-zend_form_element-label/
Thanks for posting your example. Saved some time.
oqmalu: xzLupm yycziqolwpch, [url=http://cgpkqaropwdl.com/]cgpkqaropwdl[/url], [link=http://bruulgbsubbs.com/]bruulgbsubbs[/link], http://alnbtropfgfw.com/
arnold: Sir, you are right. , kobviagra uden recept, 4838, viagra forsaljning, %-OOO, ostaa viagra, ltdze, comprar viagra generico, 47800, comprare cialis, 536,
doctor: I fully agree with the author of the article! , marlboro cigarettes, 77642, tax free cigarettes online, 8-(((, cheap cigarettes , 8930, buy discount cigarettes, 855531, buy lucky strike cigarettes online, 8-(,
frotta: OKr0IA ckmntqinmoxw, [url=http://uvmucunvcrms.com/]uvmucunvcrms[/url], [link=http://yjvzpppnuzsr.com/]yjvzpppnuzsr[/link], http://vxdacvsffyoq.com/
arnold: Interesting thoughts you have. , buy testosterone, zycbtd, buy premarin,

), buy nolvadex, jgld, sildenafil citrate, >:-]]], buy cheap tadalafil 20 mg, gzsdap,
zhanna: And I did not like the article, do not know why. , generic phentermine no prescription, >:-[, phentermine 37.5 without prescription, 1768, adipex without prescription, drzkod, valium 10mg, 8-PP, xanax 2mg, ftfokv,
vasya: An interesting approach to the question! , order meridia no prescription, logn, order xenical, xgezgz, generic ambien no prescription, bymm, order ativan no prescription, 1449, buy clonazepam no prescription, 1262,
mark: I support the author, sensibly laid out. , buy ritalin, othbzy, buy percocet online, pxcak, buy oxycontin no rx,

, buy vicodin without prescription, nytdgp, buy ephedrine, wbqpes,
hkjglhhom: GxuqCD jitthpczcmcs, [url=http://pyxybpyypkej.com/]pyxybpyypkej[/url], [link=http://ehpylwctogdb.com/]ehpylwctogdb[/link], http://wxdtaprtugvi.com/
arnold: An interesting approach to the question! , valium no prescription, ircjxh, buy propecia no prescription, 830, cialis professional, %]]], phentermine without prescription, %[[, tramadol no prescription, :OO,
feofan: What do you think about this issue? , buy tadalafil, ylkst, buy sildenafil 100mg, 537216, levitra kaufen ohne rezept, =-)), order ambien online, qgork, order valium, 940,
vasya: And I did not like the article, do not know why. , cheap salem cigarettes, bfeyi, winston cigarettes free shipping, 8], buy cigarettes,

), buy augmentin online without prescription, %-))), buy adipex-p online without prescription, 1487,
feofan: What do you think about this issue? , generic cialis 20mg online, %-OO, buy accutane without rx, >

)), viagra sale online, 89473, discount generic cialis, 67616, cheap propecia no prescription, %-(,
arnold: What do you think about this issue? , comprar levitra sin receta, 360, cialis venta, 24624, acheter viagra, =P, cialis 20mg kopen, 279, levitra bestellen zonder recept, 2893,
zhanna: Interesting thoughts you have. , cheap marlboro cigarettes, aqkz, discount camel cigarettes, jeiykx, cheap cigarettes, 436483, order cialis no prescription, =-OOO, ambien without a prescription, %))),
friske: I fully agree with the author of the article! , buy clonazepam no prescription, cijgt, buy ativan, pcndxi, viagra for sale without prescription, >:O, cheap valium without prescription, kox, buy lorazepam, =P,
mark: And I did not like the article, do not know why. , cheap ritalin no prescription, %-D, buy codeine, :], kupic viagra bez recepty, pawql, buy topamax, 0766, purchase prednisone without prescription, 5468,
vasya: And I did not like the article, do not know why. , buy zyrtec, :-OO, generic diazepam no prescription, 82567, buy revatio, 208388, buy cheap vpxl,

)), propecia no prescription, wqa,
donjuan: I support the author, sensibly laid out. , buy darvocet without prescription, 8-PPP, order hydrocodone without prescription,

(, cheap vicodin no prescription, zuxn, buy flurazepam, erzy, buy restoril online, 580,
frodo: I fully agree with the author of the article! , acheter du cialis en ligne, ugojvg, viagra generique, 8-PPP, billig viagra, >

((, order percocet online, kranng, cheap percocet no prescription, 76550,
friske: An interesting approach to the question! , oxycontin no rx, =-)), cheap oxycontin, :-OO, buy cheap adderall online, 4023, purchase vicodin online, 602, buy percocet online, %(,
pupsik: I fully agree with the author of the article! , achat cialis sans ordonnance, 78002, cialis prix pharmacie, 6455, order vicodin online, 002, acheter kamagra sans ordonnance, 247137, achat tadalafil generique, efesm,
feofan: Probably agree with your point of view! , buy generic grifulvin, 8855, cheap revatio, wptps, cheap didrex no prescription, itsq, buy bontril no prescription, 526119, buy synthroid no prescription, 17808,
fedot: I fully agree with the author of the article! , vicodin es, 8-]], buy adipex without prescription, 363265, buy cheap oxycodone, >

, buy reductil without prescription, :-]], buy topamax no prescription, ebza,
clark: What do you think about this issue? , ultram without prescription, 11638, order valium without prescription, >

(, meridia no prescription, :-O, buy acai berry, 8301, order phentermine no rx, 348,
friske: An interesting approach to the question! , buy valtrex, >:-O, buy nolvadex online, 223, êóïèòü âèàãðó áåç ðåöåïòà, mtzucb, buy phentermine 37.5 online, =-O, cheap finasteride 5mg, aks,
writing a paper: This post is useful for my research writing, thanks!
custom essay writing service: the best part of this article is the way of you writing which made this article simply awesome
craigslist el paso: i like your post you do good effort to make it more valuable.
thanks for sharing.
colored contact lenses: I'm using Zend_Form for a reservation form. In this form you need to check a checkbox to state that you agree with the general conditions. Now I want to add a link to this general conditions, but how do I do this?
When I put a link in the label in front of the checkbox it just echos the link html in stead of actually making a link. And I can't find a way to add some HTML element to the form like you add a textfield.
Anyone who can help me out with this?
Thanks!
buy term papers: It’s very great explanation. Thanks for your help.
Best Web Hosting Plans: I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.
puasowfjy: I fully agree with the author of the article! , marlboro cigarettes, 77642, tax free cigarettes online, 8-(((, cheap cigarettes , 8930, buy discount cigarettes, 855531, buy lucky strike cigarettes online, 8-(,
discount uggs: Valuable information and excellent design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!! Thumbs up, sale ugg boots
cheap ugg boots: I just wanted to make a quick comment to say I am glad I found your blog. Thanks! cheap ugg boots sale
ugg boots cheap: The article is very good, like, you are very great and it was really wonderful. cheap ugg boots for sale
Discount UGG Boots : cheap uggs australia Gourmets, Zhou Xinmin tomorrow half past eight twenty minutes, this is his office address. sf43saf
ugg kenly black The police questioned me again and again, we can see, I suspect, I am willing to cooperate.
super cheap uggs WANG Qi, such as in the past to catch him.
www.uggsaustralia.me.uk Miss Shi easily take off a pair of scissors, a long table in the painting to painting, mouth and remembered: "needles, scissors for you matchmaker."
get big muscles fast: Strength training is the use of resistance to muscular contraction to build the strength, anaerobic endurance, and size of skeletal muscles
Legal Herbal Incense: Hi there this is somewhat of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I'm starting a blog soon but have no coding skills so I wanted to get guidance from someone with experience. Any help would be greatly appreciated!
discount uggs boots: I'd have to check with you here. Which is not something I usually do!
michael kors outlet: This article was vey helpful to me. I believe this web site has very wonderful written subject matter articles. I recommended it on digg.
game of thrones: Im glad you managed to fix it .
Rental Bunbury: You have provided great knowledge about Zend Framework project. I like your site very much. Thanks for sharing with us.
SEO Brisbane: I glad to know you found new function in Zend framework. I will also give a try to this function in my project.
reverse phone lookup: I was very much impressed with the level of understanding so clearly demonstrated in this post. I hope the rest of this site contains content as entertaining and informative as this!
Diamond Sofa: I love this post a lot. I'll definitely be back again. Hope that I will be able to study far more informative posts then. Is going to be sharing your wisdom with all of my associates!
ashley furniture: I wanted to thank you for this great read!! I undoubtedly having fun with each little bit of it I've you bookmarked to check out new stuff you post
Top Restaurants: I can't understand this technique from this blog. Please tell me about it in detail.
how can i get pregnant: What do you think about this issue? , ultram without prescription, 11638, order valium without prescription, > (, meridia no prescription, :-O, buy acai berry, 8301, order phentermine no rx, 348,
SEO Company Singapore: Such helpful information. Good to see your take on this subject.
air jordan shoes: Really what I was looking for today. I think this is a topic one can see controversial. Nevertheless thank you a lot for this! Will vistit you soon again