Reputation: 1200
I've added a custom element type to render raw html into forms. In addition i do custom error handling (to highlight the errored items and add the error-msg as tooltip).
Everything works. Except my custom (raw html) elements are not being shown at all if the custom error handling methode catches an validation error.
Has someone an idea why my raw html items are being stripped out of the markup if the form validation fails?
Form:
class Sample_Form_Process extends Zend_Form
{
[...]
public function init()
{
[...]
$this->addElement('rawText', 'spacer', array(
'value' => '<br class="cl"/><div class="border-bottom"></div>',
));
[...]
}
[...]
public function highlightErrorElements()
{
foreach($this->getElements() as $element) {
if($element->hasErrors()) {
$element->setAttrib('class', 'error tooltip');
$element->setAttrib('title', $element->getMessages());
}
}
}
}
ProcessController class:
class Sample_ProcessController extends Zend_Controller_Action
{
[...]
public function addAction()
{
[...]
if ($this->getRequest()->isPost()) {
if ($form->isValid($request->getPost())) {
[...]
} else {
$form->highlightErrorElements();
}
}
}
[...]
}
RawText class to render custom form element:
class Zend_Form_Element_RawText extends Zend_Form_Element
{
public function render(Zend_View_Interface $view = null)
{
return $this->getValue();
}
}
Upvotes: 0
Views: 269
Reputation: 2147
You need to add the isValid()
method to your custom form element, to always return true
so it passes validation.
public function isValid($value)
{
return true;
}
Upvotes: 1