Is there some method that accepts inserting custom html without having to actually add form controls, even if they’re hidden and making my html a decorator?
I’m looking for something like:
$this->addCustomElement( array(
'div',
'body' => '<p>inner text</p>'
) );
I need something short and quick, I don’t want to create a new class or something overkill.
Well it’s really as simple as this:
But the problem is that when you submit the form, the form calls
$note->isValid(), which overrides the value, so if there are errors with the form, the next time you display it, the custom HTML won’t be shown. There are two easy ways to fix this, the first is to overrideisValid()in your Form class like this:But personally I find this kinda hackish way, and prefer the second option. That is to write a very simple class (this should really be part of Zend itself, I have no idea why it isn’t, since it includes a
formNoteview helper, but no element that uses it):Then you just have to do:
And everything will just work.
Other options include doing some black magic with decorators, but I really recommend you to not go down that path.