Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Splendid, I don't understand why you would have a problem with code duplication, in your 2nd link, you are performing your checks, then check if the page is a post request, then performing the checks again, yes its duplicated, but I don't understand what you are trying to explain by doing this?</p> <p>As for the form, its up to you how you use it, you could create the form object, then instead of ever out putting the form, simply pass it the data from your designers form, and use it to validate things.<br /> Or you could use custom templates for the form, OK it means you don't give the designers quite as much freedom of them designing a form and you sorting the results, but they can still do their best at it.<br /> This is the setup I use, after all I am in charge of the functionality as the programmer, the designers just make it look good what the user see's.</p> <p>So for example, if I want to create an input element I can:</p> <pre><code>$arrival_time = $this-&gt;createElement('text', 'arrival_time', array( 'required' =&gt; true, 'label' =&gt; 'Arrival Time:', )); $arrival_time-&gt;removeDecorator('HtmlTag'); $this-&gt;addElement($arrival_time); </code></pre> <p>Notice I have removed the HtmlTag decorators here - I don't need them for the markup as the designers will be arranging things for me.</p> <p>Next thing to do is tell the form to use the layout the designers have made:</p> <pre><code>$this-&gt;setDecorators(array(array('ViewScript', array('viewScript' =&gt; 'NewArrivalsForm.phtml')))); </code></pre> <p>Here my template is within the view's, script's directory. </p> <p>Now the designers have a few options. They could do:</p> <pre><code>&lt;table border="0" width="100%"&gt; &lt;tr&gt; &lt;td&gt; &lt;?php echo $this-&gt;element-&gt;arrival_time; ?&gt; &lt;/td&gt; </code></pre> <p>This will give you the following output:</p> <pre><code>&lt;td&gt; &lt;dt id="arrival_time"&gt;&lt;label for="arrival_time" class="required"&gt;Arrival Time:&lt;/label&gt;&lt;/dt&gt; &lt;input type="text" name="arrival_time" id="arrival_time" value="" /&gt; &lt;/td&gt; </code></pre> <p>If there we're an error, that would be presented as well. You could remove the decorators 'Label', 'Description' &amp; 'Errors' as well, to make it simply an input box:</p> <pre><code>&lt;td&gt; &lt;input type="text" name="arrival_time" id="arrival_time" value="" /&gt; &lt;/td&gt; </code></pre> <p>Even once you have removed the decorators, the designers could still use for example:</p> <pre><code>&lt;tr&gt; &lt;td&gt; &lt;?php echo $this-&gt;element-&gt;time_on_site-&gt;getLabel(); ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;?php echo $this-&gt;element-&gt;time_on_site ?&gt; &lt;/td&gt; </code></pre> <p>This will allow them to lay the form out exactly as they want to. But it will still allow you to use the full power of Zend_Form for your final validation checks. Take a look inside the Zend/form/element.php for all the methods you and your designers can use on the form element.</p>
 

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