« Return to Thread: Include raw HTML into Zend_Form

Re: Include raw HTML into Zend_Form

by Gordon Ross-8 :: Rate this Message:

Reply to Author | View in Thread

Thanks for that. Where should I put it ? I don't really want to slap it in the main Zend directories...

GTG

PS If ever you have the unfortunate experience to bump into me, I think I owe you a few beers....

----- Original Message -----
From: Matthew Weier O'Phinney <matthew@...>
To: fw-mvc@... <fw-mvc@...>
Sent: Wed Aug 20 18:59:38 2008
Subject: Re: [fw-mvc] Include raw HTML into Zend_Form

-- Gordon Ross <gr306@...> wrote
(on Wednesday, 20 August 2008, 06:31 PM +0100):

> On 19/08/2008 09:05, "Oscar Reales" <oreales@...> wrote:
>
> > Well, in that case, there is another option that I have though to implement
> > sometimes: extends a custom formElement that renders html. You can call this
> > element "text" - "rawHtml" or something similar. Create the formEelement,
> > the viewHelper, decorators etc.... It is much more work but once it is done,
> > you can uses it in any project.
>
> Out of all the options I've seen so far, I think this one is probably the
> best. As you say, though, it may not be the simplest. I'm starting to look
> at the existing elements to see what work is involved. I'm hoping it won't
> be too much work...

It's not. :)

In this case, I'd suggest simply extending Zend_Form_Element, and then
overriding render() to simply return the element value:

    class My_Form_Element_RawText extends Zend_Form_Element
    {
        public function render(Zend_View_Interface $view = null)
        {
            return $this->getValue();
        }
    }

And that way you can re-use it to enter arbitrary text anywhere:

    $form->addElement('rawText', 'foo', array(
        'value' => 'This is some text to insert somewhere...',
    ));

--
Matthew Weier O'Phinney
Software Architect       | matthew@...
Zend Framework           | http://framework.zend.com/

 « Return to Thread: Include raw HTML into Zend_Form