title: Zend Framework 2 - Form Validation from multiple input filters sets?
body: <p>My ZF2 uses the simple structure I've seen everywhere, with inputFilters set in the models and applied to a form during validation. But I've really hit a wall here. How do you handle validation for a form that has some fields that need validated against one model and some fields that need validated against another ?</p>
  
  <p>My scenario: I am using a single form to insert 2 entries in 2 tables of my database (adding a user, and adding a donation linked to that user). Some fields will go in one table, some others in a second table.</p>
  
  <p>Like I said, my input filters are stored at model-level. </p>
  
  <p>If my whole scenario was involving just one model/table,  for example storing one donation and nothing else, I would go as follow :</p>
  
  <pre><code>$donation = new Donation();
  
  $form-&gt;setInputFilter($donation-&gt;getInputFilter());
  $form-&gt;setData($request-&gt;getPost());
  
  if ($form-&gt;isValid()) {
  
  $donation-&gt;exchangeArray($form-&gt;getData());
  $this-&gt;getDonationTable()-&gt;saveDonation($donation);
  </code></pre>
  
  <p>I can do the above.</p>
  
  <p>But I am trying to analyse and validate the form data against two sets of inputFilters that I am gathering from 2 models. One for the data that will go to a donation model and one for the data that will go to a user. I am therefore after something like this:</p>
  
  <pre><code>$donation = new Donation();
  $user = new User();
  
  $form-&gt;setInputFilter($donation-&gt;getInputFilter());
  </code></pre>
  
  <p>Then I would add something like :(obviously doesn't exist)</p>
  
  <p><strong>$form->addInputFilter($user->getInputFilter());</strong> </p>
  
  <p>So I could continue with ...</p>
  
  <pre><code>$form-&gt;setData($request-&gt;getPost());
  
  if ($form-&gt;isValid()) {
  
      // add donation
      // add user
  </code></pre>
  
  <p>I am surprised I haven't found anything about this on the internet, is the way I am using models and inputFilters incorrect ? How do you handle validation for a form that has some fields that need validated against one model and some fields that need validated against another ?</p>