title: Argument passed to Zend\Form\Form::setInputFilter() must implement interface InputFilterInterface, null given
body: <p>Well, greeting everybody, i was just following along the zend framework 2 example code for creating an album management app (<a href="http://framework.zend.com/manual/2.0/en/user-guide/forms-and-actions.html" rel="nofollow">http://framework.zend.com/manual/2.0/en/user-guide/forms-and-actions.html</a>) but ran into the following error while testing the "add" functionallity:</p>
  
  <blockquote>
    <p>Catchable fatal error: Argument 1 passed to
    Zend\Form\Form::setInputFilter() must implement interface
    Zend\InputFilter\InputFilterInterface, null given.</p>
  </blockquote>
  
  <p>I have been checking my app code to try and solve this problem but i just simply dont see what's wrong with it, even worst, searching for the error message doesn't yield any results, which is why i'm recurring to your knowledge to try and solve this, here is my code:</p>
  
  <pre><code>SystemController.php
  
  &lt;?php
  
  
  namespace System\Controller;
  
  use Zend\Mvc\Controller\AbstractActionController;
  use Zend\View\Model\ViewModel;
  use System\Model\User;
  use System\Form\UserRegisterForm;
  
  Class SystemController extends AbstractActionController
  {
  
      protected $userTable;
  
      public function indexAction()
      {
         return new ViewModel(array(
              'system' =&gt; $this-&gt;getUserTable()-&gt;fetchAll(),
          ));
      }
  
      public function editAction()
      {
  
      }
  
      public function deleteAction()
      {
  
      }
  
      public function registerAction()
      {
          $form = new UserRegisterForm();
          $form-&gt;get('submit')-&gt;setValue('Register');
  
          $request = $this-&gt;getRequest();
          if ($request-&gt;isPost()) {
              $user = new User();
              $form-&gt;setInputFilter($user-&gt;getInputFilter());
              $form-&gt;setData($request-&gt;getPost());
  
              if ($form-&gt;isValid()) {
                  $user-&gt;exchangeArray($form-&gt;getData());
                  $this-&gt;getUserTable()-&gt;saveUser($user);
  
                  // Redirect to list of albums
                  return $this-&gt;redirect()-&gt;toRoute('system');
              }
          }
          return array('form' =&gt; $form);
      }
  
      public function loginAction()
      {
  
      }
  
      public function usersAction()
      {
  
      }
  
      public function getUserTable()
      {
          if (!$this-&gt;userTable) {
              $sm = $this-&gt;getServiceLocator();
              $this-&gt;userTable = $sm-&gt;get('System\Model\UserTable');
          }
          return $this-&gt;userTable;
      }
  }
  </code></pre>
  
  <p>The error message point out that the null is being given on the line 45, line 455 corresponds to the following code snippet:</p>
  
  <pre><code>$form-&gt;setInputFilter($user-&gt;getInputFilter());
  </code></pre>
  
  <p>From is an instance of my UserRegisterForm class</p>
  
  <pre><code>UserRegisterForm.php
  
  &lt;?php
  
  
  namespace System\Form;
  
  use Zend\Form\Form;
  
  class UserRegisterForm extends Form
  {
    public function __construct($name = null)
    {
        parent::__construct('user');
        $this-&gt;setAttribute('method', 'post');
  
        $this-&gt;add(array(
            'name' =&gt; 'id',
            'attributes' =&gt; array(
                'type'=&gt;'hidden',
            ),
        ));
  
        $this-&gt;add(array(
              'name' =&gt; 'username',
              'attributes' =&gt; array(
                  'type'  =&gt; 'text',
              ),
              'options' =&gt; array(
                  'label' =&gt; 'Username',
              ),
          ));
  
        $this-&gt;add(array(
              'name' =&gt; 'first_name',
              'attributes' =&gt; array(
                  'type'  =&gt; 'text',
              ),
              'options' =&gt; array(
                  'label' =&gt; 'First Name',
              ),
          ));
  
        $this-&gt;add(array(
              'name' =&gt; 'last_name',
              'attributes' =&gt; array(
                  'type'  =&gt; 'text',
              ),
              'options' =&gt; array(
                  'label' =&gt; 'Last Name',
              ),
          ));
  
        $this-&gt;add(array(
              'name' =&gt; 'email',
              'attributes' =&gt; array(
                  'type'  =&gt; 'text',
              ),
              'options' =&gt; array(
                  'label' =&gt; 'E-mail',
              ),
          ));
  
        $this-&gt;add(array(
              'name' =&gt; 'password',
              'attributes' =&gt; array(
                  'type'  =&gt; 'password',
              ),
              'options' =&gt; array(
                  'label' =&gt; 'Password',
              ),
          ));
  
         $this-&gt;add(array(
              'name' =&gt; 'type',
              'attributes' =&gt; array(
                  'type'  =&gt; 'text',
              ),
              'options' =&gt; array(
                  'label' =&gt; 'Type',
              ),
          ));
  
        $this-&gt;add(array(
              'name' =&gt; 'submit',
              'attributes' =&gt; array(
                  'type'  =&gt; 'submit',
                  'value' =&gt; 'Register User',
                  'id' =&gt; 'submitbutton',
              ),
          ));
    }
  
  }
  </code></pre>
  
  <p>And user is an instance of my user model</p>
  
  <pre><code>User.php
  &lt;?php
  
  
  
  namespace System\Model;
  
  use Zend\InputFilter\Factory as InputFactory;     
  use Zend\InputFilter\InputFilter;                 
  use Zend\InputFilter\InputFilterAwareInterface;   
  use Zend\InputFilter\InputFilterInterface;        
  
  
  class User implements InputFilterAwareInterface
  {
      public $id;
      public $first_name;
      public $last_name;
      public $username;
      public $email;
      public $password;
      public $type;
  
      public function exchangeArray($data)
      {
          $this-&gt;id     = (isset($data['id'])) ? $data['id'] : null;
          $this-&gt;first_name = (isset($data['first_name'])) ? $data['first_name'] : null;
          $this-&gt;last_name  = (isset($data['last_name'])) ? $data['last_name'] : null;
          $this-&gt;username = (isset($data['username'])) ? $data['username'] : null;
          $this-&gt;email = (isset($data['email'])) ? $data['email'] : null;
          $this-&gt;password = (isset($data['password'])) ? $data['password'] : null;
          $this-&gt;password = (isset($data['type'])) ? $data['type'] : null;
      }
  
      public function setInputFilter(InputFilterInterface $inputFilter)
      {
          throw new \Exception("Not used");
      }
  
      public function getInputFilter()
      {
          if (!$this-&gt;inputFilter) {
              $inputFilter = new InputFilter();
              $factory     = new InputFactory();
  
              $inputFilter-&gt;add($factory-&gt;createInput(array(
                  'name'     =&gt; 'id',
                  'required' =&gt; true,
                  'filters'  =&gt; array(
                      array('name' =&gt; 'Int'),
                  ),
              )));
  
              $inputFilter-&gt;add($factory-&gt;createInput(array(
                  'name'     =&gt; 'username',
                  'required' =&gt; true,
                  'filters'  =&gt; array(
                      array('name' =&gt; 'StripTags'),
                      array('name' =&gt; 'StringTrim'),
                  ),
                  'validators' =&gt; array(
                      array(
                          'name'    =&gt; 'StringLength',
                          'options' =&gt; array(
                              'encoding' =&gt; 'UTF-8',
                              'min'      =&gt; 3,
                              'max'      =&gt; 100,
                          ),
                      ),
                  ),
              )));
  
              $inputFilter-&gt;add($factory-&gt;createInput(array(
                  'name'     =&gt; 'first_name',
                  'required' =&gt; true,
                  'filters'  =&gt; array(
                      array('name' =&gt; 'StripTags'),
                      array('name' =&gt; 'StringTrim'),
                  ),
                  'validators' =&gt; array(
                      array(
                          'name'    =&gt; 'StringLength',
                          'options' =&gt; array(
                              'encoding' =&gt; 'UTF-8',
                              'min'      =&gt; 1,
                              'max'      =&gt; 100,
                          ),
                      ),
                  ),
              )));
  
              $inputFilter-&gt;add($factory-&gt;createInput(array(
                  'name'     =&gt; 'last_name',
                  'required' =&gt; true,
                  'filters'  =&gt; array(
                      array('name' =&gt; 'StripTags'),
                      array('name' =&gt; 'StringTrim'),
                  ),
                  'validators' =&gt; array(
                      array(
                          'name'    =&gt; 'StringLength',
                          'options' =&gt; array(
                              'encoding' =&gt; 'UTF-8',
                              'min'      =&gt; 1,
                              'max'      =&gt; 100,
                          ),
                      ),
                  ),
              )));
  
              $inputFilter-&gt;add($factory-&gt;createInput(array(
                  'name'     =&gt; 'email',
                  'required' =&gt; true,
                  'filters'  =&gt; array(
                      array('name' =&gt; 'StripTags'),
                      array('name' =&gt; 'StringTrim'),
                  ),
                  'validators' =&gt; array(
                      array(
                          'name'    =&gt; 'StringLength',
                          'options' =&gt; array(
                              'encoding' =&gt; 'UTF-8',
                              'min'      =&gt; 10,
                              'max'      =&gt; 150,
                          ),
                      ),
                  ),
              )));
  
              $inputFilter-&gt;add($factory-&gt;createInput(array(
                  'name'     =&gt; 'password',
                  'required' =&gt; true,
                  'filters'  =&gt; array(
                      array('name' =&gt; 'StripTags'),
                      array('name' =&gt; 'StringTrim'),
                  ),
                  'validators' =&gt; array(
                      array(
                          'name'    =&gt; 'StringLength',
                          'options' =&gt; array(
                              'encoding' =&gt; 'UTF-8',
                              'min'      =&gt; 6,
                              'max'      =&gt; 50,
                          ),
                      ),
                  ),
              )));
  
  
          }
  
          return $this-&gt;inputFilter;
      }
  }
  </code></pre>
  
  <p>I just don't see what is wrong with the code, for me everything is fine, this error is showing up when i try and submit a from from the register view. but i just don't understand why this is happening.</p>
  
  <pre><code>register.phtml
  
  &lt;?php
  
  $title = 'Register a new user';
  $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('system', array('action' =&gt; 'register')));
  $form-&gt;prepare();
  
  /*
  echo $this-&gt;formCollection($form);
   */
  
  echo $this-&gt;form()-&gt;openTag($form);
  echo $this-&gt;formHidden($form-&gt;get('id'));
  echo $this-&gt;formRow($form-&gt;get('username'));
  echo $this-&gt;formRow($form-&gt;get('first_name'));
  echo $this-&gt;formRow($form-&gt;get('last_name'));
  echo $this-&gt;formRow($form-&gt;get('email'));
  echo $this-&gt;formRow($form-&gt;get('password'));
  echo $this-&gt;formRow($form-&gt;get('type'));
  echo $this-&gt;formSubmit($form-&gt;get('submit'));
  echo $this-&gt;form()-&gt;closeTag();
  </code></pre>
  
  <p>Any help is appreciated, 'cause i'm just about to give up.</p>