title: Dynamically adding form elements with jQuery and Zend_Form
body: <p>I have a form in which people shall be able to add the same portion of elements with a plus-button, so that something like this is produced:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div id="person-1" class="person"&gt;
      &lt;input type="text" name="name-1" id="name-1" /&gt;
      &lt;input type="text" name="age-1" id="age-1" /&gt;
  &lt;/div&gt;
  &lt;!-- as of here, it's JS created --&gt;
  &lt;div id="person-2" class="person"&gt;
      &lt;input type="text" name="name-2" id="name-2" /&gt;
      &lt;input type="text" name="age-2" id="age-2" /&gt;
  &lt;/div&gt;
  &lt;div id="person-3" class="person"&gt;
      &lt;input type="text" name="name-3" id="name-3" /&gt;
      &lt;input type="text" name="age-3" id="age-3" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I already managed to write jquery-code that allows me to add the same elements once again with a new id (name-1, age-1, name-2, age-2, name-3, age-3, …).</p>
  
  <p>Of course, Zend_Form does not know about <strong>name-2</strong> and <strong>name-3</strong>, so it just drops them when the form contains an error and is displayed again. Neither can I access the value of <strong>name-2</strong> with <code>$form-&gt;getValue('name-2')</code>. I have to go over raw <code>$this-&gt;getRequest()-&gt;getPost()</code>.</p>
  
  <p>Is there a better method I can use to combine Zend_Form and javascript-based added form elements (of same type like an hardcoded element).</p>
  
  <p><strong>Caveat</strong>: In the real problem, it’s <code>select</code> and not <code>input</code>. Found out this could make a difference (with <code>-&gt;setIsArray(true)</code>), but using <code>select</code> would blow up the example code.</p>