public function validateRegisterAction()
 {
     $registerHomeForm = $this->serviceLocator->get('FormElementManager')->get('registerHomeForm');
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         $registerHomeForm->setData($data);
         if ($registerHomeForm->isValid()) {
             $arrInfoServiceAccount = array('service_account' => 'Tài khoản thường', 'normal' => 10, 'vip' => 10, 'hot' => 10, 'free' => 10, 'chinhchu' => 10, 'date_start' => '21-12-2014', 'date_end' => '21-12-2014');
             $config = new \ZendVN\Config\Config();
             if ($config->activeAccountEmail() == 1) {
                 $active_code = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();
                 //Kích hoạt qua email cẩn phải có mã kích hoạt
                 $status = 0;
                 //Sau khi kích hoạt tài khoản mới hoạt động được
             } else {
                 //Nếu không phải kích hoạt qua email thì không cần mã kích hoạt
                 $active_code = '';
                 $status = 1;
                 //tài khoản hoạt động được luôn
             }
             //Chống tấn công XSS
             $purifier = new \HTMLPurifier_HTMLPurifier();
             $data = array('username' => $purifier->purify($this->_viewHelper->cmsReplaceString($this->_arrPost['username'])), 'password' => md5($this->_arrPost['password']), 'email' => $purifier->purify($this->_viewHelper->cmsReplaceString($this->_arrPost['email'])), 'avatar' => '', 'fullname' => $purifier->purify($this->_viewHelper->cmsReplaceString($this->_arrPost['fullname'])), 'city_id' => 1, 'website' => '', 'phone' => $purifier->purify($this->_viewHelper->cmsReplaceString($this->_arrPost['phone'])), 'active_code' => $active_code, 'status' => $status, 'group_id' => 4, 'register_ip' => $_SERVER['REMOTE_ADDR'], 'register_date' => date('d/m/y h:i:s'), 'diachi' => '', 'info_service_account' => \Zend\Json\Json::encode($arrInfoServiceAccount));
             $lastInsertId = $this->getTable()->saveItem($data, array('task' => 'add'));
             if ($config->activeAccountEmail() == 1) {
                 $AccountActiveLink = \ZendVN\Url\CurrentDomain::get() . $this->url()->fromRoute('MVC_HomeRouter/active', array('module' => 'home', 'controller' => 'user', 'action' => 'active', 'id' => $lastInsertId, 'code' => $active_code));
                 $this->sendMail($this->_arrPost['fullname'], 'Bất động sản', $this->_arrPost['email'], $this->_arrPost['password'], $AccountActiveLink);
                 $result['messages']['success'] = 'Một email vừa được gửi tới ' . $this->_arrPost['email'] . ' Với một mã kích hoạt. Bạn vui lòng kiểm tra email để kích hoạt tài khoản';
             } else {
                 $result['messages']['success'] = 'Chúc mừng bạn đã đăng kí thành công';
             }
             $result['status'] = 'success';
         } else {
             $result['status'] = 'error';
             $result['messages']['fullname'] = current($registerHomeForm->getMessages('fullname'));
             $result['messages']['username'] = current($registerHomeForm->getMessages('username'));
             $result['messages']['password'] = current($registerHomeForm->getMessages('password'));
             $result['messages']['confirmpassword'] = current($registerHomeForm->getMessages('confirm-password'));
             $result['messages']['email'] = current($registerHomeForm->getMessages('email'));
             $result['messages']['phone'] = current($registerHomeForm->getMessages('phone'));
             $result['messages']['captcha'] = '';
             if (current($registerHomeForm->getMessages('captcha')) != '') {
                 $result['messages']['captcha'] = 'Mã an toàn không chính xác';
             }
         }
     }
     echo \Zend\Json\Json::encode($result);
     return $this->getResponse();
 }