title: Inserting data From Zend's form to database
body: <p>I have a problem with inserting Records into a DB using Zend FrameWork 2.
  There are no records saved into the DB when submitting the Form and also no Error Messages Appear,  just the Confirmation Message telling me that it <code>&lt;&lt; Registered Successfully &gt;&gt;</code>
  Here is my code, thanks in advance:</p>
  
  <pre><code> // App/config/autoload/global.php
   return array(
         'db'   =&gt; array(
              'driver'         =&gt; 'pdo',
              'dsn'            =&gt;  'mysql:dbname=zf_app;host=localhost;port:8080',
              'username'       =&gt; 'zf_user',
              'password'       =&gt; 'zf_pass',
              'driver_options' =&gt; array(
                              PDO::MYSQL_ATTR_INIT_COMMAND =&gt; 'SET NAMES \'UTF8\''
                              ),
  
                      ),
        'service_manager'   =&gt; array(
              'factories'   =&gt; array(
                          'Zend\Db\Adapter\Adapter' =&gt;'Zend\Db\Adapter\AdapterServiceFactory',
                          ),
              ),
   );
  
     #################################################################
  
   //App\module\Users\src\Users\Model\Usertable.php
  
     &lt;?php
  
  namespace Users\Model;
  use Zend\Db\Adapter\Adapter;
  use Zend\Db\ResultSet\ResultSet;
  use Zend\Db\TableGateway\TableGateway;
  
  class UserTable
  {
  protected $tableGateway ;
  
  public function __construct(TableGateway $tableGateway)
  {
      $this-&gt;tableGateway = $tableGateway;
  }
  
  public function saveUser(User $user)
  {
      $data = array(
              'email'     =&gt; $user-&gt;email ,
              'name'      =&gt; $user-&gt;name,
              'password'  =&gt; $user-&gt;password,
          );
  
      $id = (int)$user-&gt;id ;
      if($id == 0)
      {
          $this-&gt;tableGateway-&gt;insert($data);
      } else {
          if($this-&gt;getUser($id))
          {
              $this-&gt;tableGateway-&gt;update($data , array('id' =&gt; $id));
          } else {
              throw new \Exception("User ID does not Exist ");
  
          }
      }
  }
  
  public function getUser($id)
  {
      $id      = (int)$id;
      $rowset  = $this-&gt;tableGateway-&gt;select(array('id' =&gt; $id ));
      $row     = $rowset-&gt;current();
  
      if(!$row)
      {
          throw new \Exception("Could not Find row $id ");
      }
      return $row ;
    }
  
  }
  
  
  
     ##########################################################
    // App\module\Users\src\Users\Controller\RegisterController.php
  
       &lt;?php
  
   namespace Users\Controller;
   use Zend\Mvc\Controller\AbstractActionController;
   use Zend\View\Model\ViewModel;
   use Users\Form\RegisterForm;
   use Users\Form\RegisterFilter;
   use Zend\Db\Adapter\Adapter;
  
  
  class RegisterController extends AbstractActionController
  {
    public function indexAction()
    {
        $form      = new RegisterForm();
        $viewModel = new ViewModel(array('form' =&gt; $form));
        return $viewModel;
    }
  
  
    public function confirmAction()
    {
        $viewModel = new ViewModel();
        return $viewModel;
    }
  
  
    public function processAction()
    {
        if(!$this-&gt;request-&gt;isPost())
        {
            return $this-&gt;redirect()-&gt;toRoute(NULL , array(
                                                        'controller'   =&gt; 'register',
                                                      'action'       =&gt; 'index',
                                                        ));
        }
  
        $post = $this-&gt;request-&gt;getPost();
        $form = new RegisterForm();
        $inputFilter = new RegisterFilter();
        $form-&gt;setInputFilter($inputFilter);
        $form-&gt;setData($post);
  
        if (!$form-&gt;isValid())
        {
            $model = new ViewModel(array('error' =&gt; true , 'form' =&gt; $form));
            $model-&gt;setTemplate('users/register/index');
            return $model;
        }
  
        return $this-&gt;redirect()-&gt;toRoute(NULL , array('controller' =&gt; 'register'  , 'action' =&gt; 'confirm' ,));
  
    }
  
  
    public function createUser(array $data)
    {
        $sm                  = $this-&gt;getServiceLocator();
        $dbAdapter           = $sm-&gt;get('Zend\Db\Adapter\Adapter');
        $resultSetPrototype  = new \Zend\Db\ResultSet\ResultSet();
  
        $resultSetPrototype-&gt;setArrayObjectPrototype(new \Users\Model\User);
        $tableGateway = new \Zend\Db\TableGateway\TableGateway('user' ,  $dbAdapter , null , $resultSetPrototype);
  
         $user   = new User();
         $user-&gt;exchangeArray($data);
         $userTable = new UserTable($tableGateway);
         $userTable-&gt;saveUser($user);
         $this-&gt;createUser($form-&gt;getData());
         return true;
       }
  
  
  
   }
  </code></pre>