title: Loading a Zend Form via Ajax Call
body: <p>I have a requirement to load a form into a page dynamically, with the potential for multiple instances of this form. Validating and saving is not a problem, but I cannot seem to pass back the actual form content / mark-up from the Controller. When testing with simple values (id: 1) I can return the data successfully, but the actual form is always returned as undefined if the datatype is not set, or [Object object].</p>
  
  <p>Controller:</p>
  
  <pre><code>public function addPermissionFormAction()
  {
      $this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender();
      $this-&gt;_helper-&gt;layout-&gt;disableLayout();
      //data from ajax call is successfully received
      $username = $this-&gt;getRequest()-&gt;getParam('user');
      //...Code to get $pages...
      $form = new Pds_Wizard_SubForm_Externals($pages);
  
      if(!isset($form)) $form = false;
      //I have run XDebug to here and confirmed that the form is built successfully.
      echo Zend_Json::encode(array('form' =&gt; $form));
  }
  </code></pre>
  
  <p>My Ajax Call:</p>
  
  <pre><code>$('#get-player-permissions').click(function() {
      if($('#test-test').val().length &gt; 0) {
          $.ajax({
          url: '/pds/external-user/add-permission-form',
          data: { user: $('#test-test').val() },
          dataType: 'json',
          contentType: "application/json",
          success: function(data){
              alert(data.form); // [Object object]
              $("#wizardContainer").html(data.form); //empty, no form content
          }
      })
      } 
  });
  </code></pre>
  
  <p>I have tried this without even adding the <strong>dataType</strong> or <strong>contentType</strong> fields for sending simple values, and have no issue getting those through. With the form, however, I will get a null or undefined in this case.</p>
  
  <p>Any advice is appreciated, including more ideal methods of dynamically loading a form. I do not use Ajax calls very often, so if this is a simple mistake I apologize. Thank you in advance!</p>