title: Zend Form Binding with Multiple Tables
body: <p>In my Zend application i have separate models for each table and data is retrieved using <code>TableGateway</code> </p>
  
  <p>Now i need to implement form to create edit page. I could able to create form of one table/model as mentioned in <a href="http://framework.zend.com/manual/2.2/en/user-guide/forms-and-actions.html" rel="nofollow">http://framework.zend.com/manual/2.2/en/user-guide/forms-and-actions.html</a></p>
  
  <p>Here is my edit action -</p>
  
  <pre><code>public function editAction()
  {
      $id = (int) $this-&gt;params()-&gt;fromRoute('id', 0);
  
      if (!$id) {
          return $this-&gt;redirect()-&gt;toRoute('candidate', array(
              'action' =&gt; 'index'
          ));
      }
  
      try {
          $candidate = $this-&gt;getCandidateTable()-&gt;getCandidate($id);
      }
      catch (\Exception $ex) {
          return $this-&gt;redirect()-&gt;toRoute('candidate', array(
              'action' =&gt; 'index'
          ));
      }
  
      $form  = new CandidateForm();
      $form-&gt;bind($candidate);
      $form-&gt;get('submit')-&gt;setAttribute('value', 'Edit');
  
      $request = $this-&gt;getRequest();
      if ($request-&gt;isPost()) {
          $form-&gt;setInputFilter($candidate-&gt;getInputFilter());
          $form-&gt;setData($request-&gt;getPost());
  
          if ($form-&gt;isValid()) {
              $this-&gt;getCandidateTable()-&gt;saveCandidate($candidate);
              return $this-&gt;redirect()-&gt;toRoute('candidate');
          }
      }
  
      return array(
          'id' =&gt; $id,
          'form' =&gt; $form,
      );
  
  }
  </code></pre>
  
  <p>edit view -</p>
  
  <pre><code>&lt;?php
  $title = 'Edit Candidate';
  $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;
  $form-&gt;setAttribute('action', $this-&gt;url(
      'candidate',
      array(
          'action' =&gt; 'edit',
          'id'     =&gt; $this-&gt;id,
      )
  ));
  $form-&gt;prepare();
  
  echo $this-&gt;form()-&gt;openTag($form);
  echo $this-&gt;formHidden($form-&gt;get('id'));
  echo $this-&gt;formRow($form-&gt;get('title'));
  echo $this-&gt;formSubmit($form-&gt;get('submit'));
  echo $this-&gt;form()-&gt;closeTag();
  </code></pre>
  
  <p>This edit action binds a form with one table (CandidateTable). But in my application, that page has data from multiple tables (CandidateSkills, CandidateQualifications etc). When i click submit it should save data in separate tables.</p>