开发者

Get name of a Zend_Form_Element in FormErrors Helper

开发者 https://www.devze.com 2023-03-13 05:03 出处:网络
I have a MyNameSpace_View_Helper_FormErrors Class which extends the standard FormErrors Class and sets the HTML for the ErrorMessage itself.

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 t开发者_StackOverflowhe 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 ?


you are probably speaking about the Errors decorator. However there is additional FormErrors decorator that renders all the errors of the form (not single element)

In element decorators you can access the element by $this->getElement()

in the element ViewScripts you can access the element by <? $this->element ?>


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 :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消