Search code examples
phpzend-frameworkzend-formzend-form-elementview-helpers

Get name of a Zend_Form_Element in FormErrors Helper


I have a MyNameSpace_View_Helper_FormErrors Class which extends the standard FormErrors Class and sets the HTML for the ErrorMessage itself.

I have to give the errormessage container an id based on the name of the element for which the error is thrown.

<ul id='errormsg_$ELEMENTNAME'>

It seems the View_Helper_FormErrors has no "link" to the Element, so is there any way to get the name or object of the Element which throws the error ?


Solution

  • I will also have to overwrite Zend_Form_Decorator_Error to give the Element to the View Helper.

    see Zend_Form_Decorator_Error line 60:

    $errors    = $view->formErrors($errors, $this->getOptions());
    

    will change to:

    $errors    = $view->formErrors($errors, $this->getOptions(), $this->getElement());
    

    Tanks to @venimus , without his answer i wouldnt have looked in the decorator :-)