2017-04-13 142 views
0

在我的codeigniter版本3.1.4/hmvc登錄如果由於某種原因表單驗證密碼輸入爲空回調函數首先顯示而不是所需的消息?Codeigniter&HMVC Callback首先顯示

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

上的消息顯示它應該顯示所需的密碼信息第一次,而不是回調

enter image description here

問題我怎樣才能確保它顯示了正確的驗證消息 第一。

自動加載form_validation

$autoload['libraries'] = array('database', 'form_validation'); 

控制器

<?php 

class Login extends MX_Controller { 

    public $CI; 

    public function __construct() { 
     parent::__construct(); 
     $this->load->model('catalog/user/user_model'); 

     $this->form_validation->CI =& $this; 
    } 

    public function index() { 
     $data['type'] = $this->input->post('type'); 
     $data['password'] = $this->input->post('password'); 

     $this->form_validation->set_rules('type', 'Username Or Email', 'trim|required'); 
     $this->form_validation->set_rules('password', 'password', 'required|callback_validatePassword[password]'); 

     if ($this->form_validation->run() == false) { 

      $data['header'] = Modules::run('catalog/common/header/index'); 
      $data['footer'] = Modules::run('catalog/common/footer/index'); 

      $this->load->view('template/account/login', $data); 

     } else { 

      $user_info = $this->user_model->get_user($user_id = '', $this->input->post('type', true)); 

      if ($user_info) { 

       $remember = $this->input->post('remember') ? TRUE : FALSE; 

       $this->user->login($user_info['user_id'], $remember); 

       redirect(base_url("users") .'/'. $user_info['user_id'] .'/'. $user_info['username']); 
      } 
     } 
    } 

    public function validatePassword($str) { 
     if ($this->user_model->validate_password($str, $this->input->post('type', true))) { 
      return TRUE; 
     } else { 
      $this->form_validation->set_message('validatePassword', 'Opp\'s somthing wrong with login!'); 
      return FALSE; 
     } 
    } 
} 

應用>庫> MY_Form_validation.php

<?php 

class MY_Form_validation extends CI_Form_validation { 

    public $CI; 

} 

回答

0
just keep the callback validation separate 
$this->form_validation->set_rules('password', 'password', 'trim|required'); 
// check for post values is empty or not? 
if(!empty($data['password'])) { 
    $this->form_validation->set_rules('password', 'password', 'callback_validatePassword[password]'); 
} 
+0

這是爲什麼任何理由 – user4419336

+0

我仍然有同樣的問題 – user4419336

+0

您可以刪除微調功能,並嘗試.... – 438sunil