Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There's a few ways. You can roll your own element view helpers (which could get rather clumsy soon I guess).</p> <p>Or... you could use a viewscript for the form, like this (very basic example):</p> <pre><code>class Your_Form extends Zend_Form { public function init() { $this-&gt;setDecorators( array( 'PrepareElements', array( 'ViewScript', array( 'viewScript' =&gt; 'path/to/viewscript.phtml' ) ) ) ); // only use basic decorators for elements $decorators = array( 'ViewHelper', 'Label', 'Errors' ); // create some element $someElement = new Zend_Form_Element_Text( 'someElement' ); // set the basic decorators for this element and set a css class $someElement-&gt;setDecorators( $decorators ) -&gt;setAttrib( 'class', 'someCssClass' ); // add (potentially multiple) elements to this from $this-&gt;addElements( array( $someElement ) ); } } </code></pre> <p>See the <a href="http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.prepareElements" rel="nofollow noreferrer">standard decorators section about PrepareElements</a> for why it's needed to have the PrepareElements decorator set for the form, when using the ViewScript decorator.</p> <p>Then in the viewscript:</p> <pre><code>&lt;? // the form is available to the viewscript as $this-&gt;element $form = $this-&gt;element; ?&gt; &lt;!-- put whatever html you like in this script and render the basic element decorators seperately --&gt; &lt;div&gt; &lt;? if( $form-&gt;someElement-&gt;hasErrors() ): ?&gt; &lt;?= $form-&gt;someElement-&gt;renderErrors() ?&gt; &lt;? endif; ?&gt; &lt;?= $form-&gt;someElement-&gt;renderLabel(); ?&gt; &lt;?= $form-&gt;someElement-&gt;renderViewHelper(); ?&gt; &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload