Zend: Quick and succinct way of inserting custom HTML into a Zend_Form? -


is there method accepts inserting custom html without having add form controls, if they're hidden , making html decorator?

i'm looking like:

$this->addcustomelement( array( 'div',  'body' => '<p>inner text</p>' ) ); 

i need short , quick, don't want create new class or overkill.

well it's simple this:

$note = new zend_form_element('note'); $note->helper = 'formnote'; $note->setvalue('<b>hi</b>'); $form->addelement($note); 

but problem when submit form, form calls $note->isvalid(), overrides value, if there errors form, next time display it, custom html won't shown. there 2 easy ways fix this, first override isvalid() in form class this:

public function isvalid($data) {     $note = $this->note->getvalue();     $valid = parent::isvalid($data);     $this->note->setvalue($note);     return $valid; } 

but find kinda hackish way, , prefer second option. write simple class (this should really part of zend itself, have no idea why isn't, since includes formnote view helper, no element uses it):

class my_form_element_note extends zend_form_element_xhtml {     public $helper = 'formnote';     public function isvalid($value, $context = null) { return true; } } 

then have do:

$note = new my_form_element_note('note'); $note->setvalue('<b>hi</b>'); $form->addelement($note); 

and work.

other options include doing black magic decorators, recommend not go down path.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -