How does one add a 'plain text node' to a zend form?

Mallika Iyer picture Mallika Iyer · Mar 4, 2010 · Viewed 14.5k times · Source

I'm trying to add a plain text node in a zend form - the purpose is to only dispay some static text.

The problem is - im not aware of any such way to do it.

I have used 'description' but that HAS to be attached to a form element.

Is there any way to simply display some text as part of a form? Zend considers everything as a form element so I cannot just print it out.

Eg:

The following will test your ability on so and so. . . .

etc...

Any thoughts?

Answer

Aine picture Aine · Oct 12, 2010

Zend has a form note view helper (Zend_View_Helper_FormNote), which you can use to add text.

Just create a new form element (/application/forms/Element/Note.php):

class Application_Form_Element_Note extends Zend_Form_Element_Xhtml  
{  
    public $helper = 'formNote';  
}

In your form:

$note = new Application_Form_Element_Note(
    'test',
    array('value' => 'This is a <b>test</b>')
);
$this->addElement($note);