Problems with Zend Form Decorators

How can I achieve the following: using form decorators for form elements:

<dt> <ul> <li>The errors</li> <li>The errors</li> </ul> <label>The label</label> </dt> <dd> <input type="text" value="The input field"> </dd> 

In other words, instead of the errors added after the input field, I want them to be added before the label. However, I want to keep the <dt> and <dd> tags as shown above.

+4
source share
2 answers

Ok, I found out how to do it. Gradually, decorators begin to understand me:

 $decorators = array( 'Label', array( 'Errors', array( 'placement' => 'prepend' ) ), array( array( 'dt' => 'HtmlTag' ), array( 'tag' => 'dt' ) ), array( array( 'ddOpen' => 'HtmlTag' ), array( 'tag' => 'dd', 'openOnly' => true, 'placement' => 'append' ) ), array( 'ViewHelper' ), array( array( 'ddClose' => 'HtmlTag' ), array( 'tag' => 'dd', 'closeOnly' => true, 'placement' => 'append' ) ) ); 

What does it mean:

  • First write
  • Then add (default = add) Errors
  • Wrap (default) all previous content in an HtmlTag (dt)
  • Next, append (default = wrap) opening the HtmlTag (dd)
  • Then add (default) ViewHelper
  • Then add (default = wrap) closing the HtmlTag (dd)

Then install the decorators:

 // be sure to only set them, after you have added the relevant elements to the form $this->setElementDecorators( $decorators ); 

PS:
Keep in mind that in my specific example invalid html is created. ;-) I found out later that <ul> elements are not allowed in <dt> elements with DOCTYPE HTML 4.01 strict

+5
source

In your form class, try the following:

 $this->setElementDecorators(array( 'Errors', 'ViewHelper', 'Label', )); 
0
source

Source: https://habr.com/ru/post/1299317/


All Articles