Note that there are some explanatory texts on larger screens.

plurals
  1. POZF2 Vertical Form
    primarykey
    data
    text
    <p>I created a simple form in typical ZF2 application. The form class code is just a modified code provided by Zend's Album example.</p> <pre><code>&lt;?php namespace Admin\Form; use Zend\Form\Form; class CityForm extends Form { public function __construct($name = null) { parent::__construct('city'); $this-&gt;setAttribute('method', 'post'); $this-&gt;add(array( 'name' =&gt; 'id', 'attributes' =&gt; array( 'type' =&gt; 'hidden', ), )); $this-&gt;add(array( 'name' =&gt; 'name', 'attributes' =&gt; array( 'type' =&gt; 'text' ), 'options' =&gt; array( 'label' =&gt; 'Name', ), )); $this-&gt;add(array( 'name' =&gt; 'province', 'attributes' =&gt; array( 'type' =&gt; 'text' ), 'options' =&gt; array( 'label' =&gt; 'Province', ), )); $this-&gt;add(array( 'name' =&gt; 'country', 'attributes' =&gt; array( 'type' =&gt; 'text' ), 'options' =&gt; array( 'label' =&gt; 'Country', ), )); $this-&gt;add(array( 'name' =&gt; 'coordinate', 'attributes' =&gt; array( 'type' =&gt; 'text' ), 'options' =&gt; array( 'label' =&gt; 'Coordinate', ), )); $this-&gt;add(array( 'name' =&gt; 'submit', 'attributes' =&gt; array( 'type' =&gt; 'submit', 'value' =&gt; 'Save', 'id' =&gt; 'submitButton', ), )); } } </code></pre> <p>And call it like this in CityController, a typical controller extends AbstractActionController:</p> <pre><code>public function addAction() { $form = new CityForm(); $viewData = array( 'form' =&gt; $form ); return new ViewModel($viewData); } </code></pre> <p>Finally in view I echo it like this:</p> <pre><code>&lt;?php $title = 'Add New City'; ?&gt; &lt;?php $this-&gt;headtitle($title); ?&gt; &lt;h1&gt;&lt;?php echo $this-&gt;escapehtml($title); ?&gt;&lt;/h1&gt; &lt;?php $form = $this-&gt;form; ?&gt; &lt;?php $form-&gt;setAttribute('action', $this-&gt;url('city', array('action' =&gt; 'add'))); ?&gt; &lt;?php $form-&gt;prepare(); ?&gt; &lt;?php echo $this-&gt;form()-&gt;openTag($form); echo $this-&gt;formHidden($form-&gt;get('id')); echo $this-&gt;formRow($form-&gt;get('name')); echo $this-&gt;formRow($form-&gt;get('province')); echo $this-&gt;formRow($form-&gt;get('country')); echo $this-&gt;formRow($form-&gt;get('coordinate')); echo $this-&gt;formSubmit($form-&gt;get('submit')); echo $this-&gt;form()-&gt;closeTag(); ?&gt; </code></pre> <p>What I expected to see is a vertical form like this: <img src="https://i.stack.imgur.com/ilwxw.png" alt="Awesome vertical form"></p> <p>But what i got is an ugly form like this: <img src="https://i.stack.imgur.com/ZfEJR.png" alt="Yikes!"></p> <p>What's wrong with my code? Please help.</p> <p>EDIT:</p> <p>When I inspect element, the form generated is strange. The <code>&lt;input&gt;</code> element is inside the <code>&lt;label&gt;</code> element.</p> <pre><code>&lt;form id="city" name="city" method="post" action="/karciscus/public/admin/city/add"&gt; &lt;input type="hidden" value="" name="id"&gt; &lt;label&gt; &lt;span&gt;Name&lt;/span&gt;&lt;input type="text" value="" name="name"&gt; &lt;/label&gt; &lt;label&gt; &lt;span&gt;Province&lt;/span&gt;&lt;input type="text" value="" name="province"&gt; &lt;/label&gt; &lt;label&gt; &lt;span&gt;Country&lt;/span&gt;&lt;input type="text" value="" name="country"&gt; &lt;/label&gt; &lt;label&gt; &lt;span&gt; Coordinate&lt;/span&gt;&lt;input type="text" value="" name="coordinate"&gt; &lt;/label&gt; &lt;input type="submit" value="Save" id="submitButton" name="submit"&gt; &lt;/form&gt; </code></pre> <p>I'm pretty sure it is the cause of my ugly rendered form. I think it is not supposedly like that. How to fix it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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