title: Zend Framework 2 InputFilter error when insert and update data
body: <blockquote>
    <p>Catchable fatal error: Argument 1 passed to
    Zend\Form\Form::setInputFilter() must implement interface
    Zend\InputFilter\InputFilterInterface, null given, called in
    C:\xampp\htdocs\pizza\module\Pizza\src\Pizza\Controller\PizzaController.php
    on line 52 and defined in
    C:\xampp\htdocs\pizza\vendor\zendframework\zendframework\library\Zend\Form\Form.php
    on line 652</p>
  </blockquote>
  
  <p>this is the file : </p>
  
  <pre><code> &lt;?php
  namespace Pizza\Controller;
  
  use Zend\Mvc\Controller\AbstractActionController;
  
  use Pizza\Form\AddPizzaForm;
  
  use Pizza\Form\EditPizzaForm;
  
  use Zend\View\Model\ViewModel;
  
  use Pizza\Model\Pizza;
  
  use Zend\View\Model\JSonModel;
  
  
  class PizzaController extends AbstractActionController{
      protected $pizzaTable;
  
      public function indexAction()
      {
          return new ViewModel(array('pizzas' =&gt; $this-&gt;getPizzaTable()-&gt;find_all()));
      }
  
      public function addAction()
      {
          $add_form = new AddPizzaForm();
          $request = $this-&gt;getRequest();
          if ($request-&gt;isPost()) {
  
              $pizza = new Pizza();
              $add_form-&gt;setInputFilter($pizza-&gt;getInputFilter());
              $add_form-&gt;setData($request-&gt;getPost());
  
              if ($add_form-&gt;isValid()) {
                  $pizza-&gt;exchangeArray($add_form-&gt;getData());
                  $this-&gt;getPizzaTable()-&gt;save($pizza);
              }
  
              return $this-&gt;redirect()-&gt;toRoute('pizza');
          }
  
          return array('form' =&gt; $add_form);
      }
  
      public function editAction()
      {
          $id = (int) $this-&gt;params()-&gt;fromRoute('id',0);
          if ($id == 0) {
              //redirect to index action Route.
              return $this-&gt;redirect()-&gt;toRoute('pizza');
  
          }else{
  
              $pizza      = $this-&gt;getPizzaTable()-&gt;find_by_id($id);
              $edit_form  = new EditPizzaForm();
              $edit_form-&gt;bind($pizza);
  
              $request = $this-&gt;getRequest();
              if ($request-&gt;isPost()) {
                  $edit_form-&gt;setInputFilter($pizza-&gt;getInputFilter());
                  $edit_form-&gt;setData($request-&gt;getPost());
  
                  if ($edit_form-&gt;isValid()) {
                      $this-&gt;getPizzaTable()-&gt;save($pizza);
                      return $this-&gt;redirect()-&gt;toRoute('pizza');   
                  }
              }
  
              return array('id'=&gt; $id,'form' =&gt; $edit_form);
          }
      }
  
      public function deleteAction()
      {
          $id = (int) $_POST['id'];
          $this-&gt;getPizzaTable()-&gt;delete($id);
          $msg = "good";
  
          $response = new JSonModel(array('response' =&gt; $msg));
  
          return $response;
      }
  
      public function getPizzaTable()
      {
          if (!$this-&gt;pizzaTable) {
              $sm = $this-&gt;getServiceLocator();
              $this-&gt;pizzaTable = $sm-&gt;get('Pizza\Model\PizzaTable');
          }
  
          return $this-&gt;pizzaTable;
      }
  }
  </code></pre>
  
  <p>the Model File : Pizza</p>
  
  <pre><code>&lt;?php
  
  namespace Pizza\Model;
  use Zend\InputFilter\InputFilter;
  use Zend\InputFilter\InputFilterInterface;
  use Zend\InputFilter\InputFilterAwareInterface;
  
  class Pizza implements InputFilterAwareInterface
  {
      public $id;
      public $name;
      public $ingredients;
      public $smallprice;
      public $bigprice;
      public $familyprice;
      public $partyprice;
  
      protected $inputFilter;
  
      public function __construct(){
  
      }
  
      public function exchangeArray($data){
  
          $this-&gt;id           = (!empty($data['id']))          ? $data['id']          : null;
          $this-&gt;name         = (!empty($data['name']))        ? $data['name']        : null;
          $this-&gt;ingredients  = (!empty($data['ingredients'])) ? $data['ingredients'] : null;
          $this-&gt;smallprice   = (!empty($data['smallprice']))  ? $data['smallprice']  : null;
          $this-&gt;bigprice     = (!empty($data['bigprice']))    ? $data['bigprice']    : null;
          $this-&gt;familyprice  = (!empty($data['familyprice'])) ? $data['familyprice'] : null;
          $this-&gt;partyprice   = (!empty($data['partyprice']))  ? $data['partyprice']  : null;
      }
  
      public function getArrayCopy(){
  
          return get_object_vars($this);
      }
  
      public function setInputFilter(InputFilterInterface $inputfilter){
  
          throw new \Exception("not Used");
  
  
      }
  
      public function getInputFilter(){
  
          if (!$this-&gt;inputFilter) {
  
              $inputfilter = new InputFilter();
  
              $inputfilter-&gt;add(array(
                  'name'      =&gt; 'name',
                  'required'  =&gt; true,
                  'filters'   =&gt; array(
                      array('name'  =&gt; 'StringTrim'),
                      array('name'  =&gt; 'StripTags')
                      ),
                  'validators'=&gt; array(
                      array('name'   =&gt; 'StringLength',
                      'options'=&gt; array(
                          'encoding'  =&gt; 'UTF-8',
                          'min'       =&gt; 5,
                          'max'       =&gt;30,
                          ))
                      )
                  ));
  
              $inputfilter-&gt;add(array(
                  'name'=&gt; 'ingredients',
                  'required'  =&gt; true,
                  'filters'   =&gt; array(
                      array('name'  =&gt; 'StringTrim'),
                      array('name'  =&gt; 'StripTags')
                      ),
                  'validators'=&gt; array(
                      array('name'   =&gt; 'StringLength',
                      'options'=&gt; array(
                          'encoding'  =&gt; 'UTF-8',
                          'min'       =&gt; 5,
                          'max'       =&gt;255,
                          ))
                      )
                  ));
  
              $inputfilter-&gt;add(array(
                  'name'      =&gt; 'smallprice',
                  'required'  =&gt; true,
                  'filters'   =&gt; array(
                      array('name'  =&gt; 'StringTrim'),
                      array('name'  =&gt; 'StripTags')
                      ),
                  'validators'=&gt; array(
                      array('name'   =&gt; 'StringLength',
                      'options'=&gt; array(
                          'encoding'  =&gt; 'UTF-8',
                          'min'       =&gt; 1,
                          'max'       =&gt; 5,
                          ))
                      )
                  ));
  
              $inputfilter-&gt;add(array(
                  'name'      =&gt; 'bigprice',
                  'required'  =&gt; true,
                  'filters'   =&gt; array(
                      array('name'  =&gt; 'StringTrim'),
                      array('name'  =&gt; 'StripTags')
                      ),
                  'validators'=&gt; array(
                      array('name'   =&gt; 'StringLength',
                      'options'=&gt; array(
                          'encoding'  =&gt; 'UTF-8',
                          'min'       =&gt; 1,
                          'max'       =&gt; 5,
                          ))
                      )
                  ));
  
              $inputfilter-&gt;add(array(
                  'name'  =&gt; 'familyprice',
                  'required'  =&gt; true,
                  'filters'   =&gt; array(
                      array('name'  =&gt; 'StringTrim'),
                      array('name'  =&gt; 'StripTags')
                      ),
                  'validators'=&gt; array(
                      array('name'   =&gt; 'StringLength',
                      'options'=&gt; array(
                          'encoding'  =&gt; 'UTF-8',
                          'min'       =&gt; 1,
                          'max'       =&gt; 5,
                          ))
                      )
                  ));
  
              $inputfilter-&gt;add(array(
                  'name'=&gt; 'partyprice',
                  'required'  =&gt; true,
                  'filters'   =&gt; array(
                      array('name'  =&gt; 'StringTrim'),
                      array('name'  =&gt; 'StripTags')
                      ),
                  'validators'=&gt; array(
                      array('name'   =&gt; 'StringLength',
                      'options'=&gt; array(
                          'encoding'  =&gt; 'UTF-8',
                          'min'       =&gt; 1,
                          'max'       =&gt; 5,
                          ))
                      )
                  ));
  
              $this-&gt;inputFilter = $inputfilter;
  
          }else{
              return $this-&gt;inputFilter;
          }
  
      }
  }
  </code></pre>