title: Add a subform to a form with ajax on submit
body: <p>I read this article:
  <a href="http://www.jeremykendall.net/2009/01/19/dynamically-adding-elements-to-zend-form/" rel="nofollow">http://www.jeremykendall.net/2009/01/19/dynamically-adding-elements-to-zend-form/</a></p>
  
  <p>That was very interesting and it works fine.</p>
  
  <p>I need to do the same but with a SubForm. I mean that when a user presses a button, I call, via ajax, an action that adds, attaches and displays a subform to my existing form.</p>
  
  <p>For example:<br>
  I have a form where a user must fill in the name and surname of his children, so there is a button "Add Child". When the user presses that button a SubForm should be added to my existing form and displayed. On submit it will validate exactly like the example in that article.  The only difference is that in there he just adds a single field. I need to add a SubForm, but in exactly the same way.</p>
  
  <p>I tried the following in my action ( called by Ajax ):</p>
  
  <pre><code>public function clonerecursivegroupAction()
  {
      $this-&gt;_helper-&gt;layout-&gt;disableLayout();
      $ajaxContext = $this-&gt;_helper-&gt;getHelper('AjaxContext');
      $ajaxContext-&gt;addActionContext('clonerecursivegroup', 'html')-&gt;initContext();
  
      $id = $this-&gt;_getParam('id', null);
  
      $subform1 = new Zend_Form_SubForm();
  
      $Element1 = $subform1-&gt;createElement('text', 'text1');
      $Element1-&gt;setLabel('text1')-&gt;setRequired(true);
      $Element2 = $subform1-&gt;createElement('text', 'text2');
      $Element2-&gt;setLabel('text2')-&gt;setRequired(false);
  
      $subform1-&gt;addElement($Element1);
      $subform1-&gt;addElement($Element2);
  
      $this-&gt;view-&gt;field = $subform1-&gt;__toString();
  }
  </code></pre>
  
  <p>This almost works.<br>
  The view of this action returns the html code of the SubForm, so on success of my ajax call I just display it.</p>
  
  <p>The problem is that on submit it validates the form but it has lost the new subform just added. That does not happen in the article with just one element. I think I just need to add the SubForm to the existing Form, but how?</p>