2015-06-18 25 views
1

我有自動加載輔助形式和autoload.php庫形式驗證無法獲得form_validation-> set_rules和form_validation-> set_message錯誤

<?php 
    defined('BASEPATH') OR exit('No direct script access allowed'); 

class Login extends CI_Controller { 


    var $data; 
    public function __construct(){ 
     parent::__construct(); 
     $this->data=array('page'=>'login_view','title'=>'login'); 
      $this->load->model("Login_model"); 

    } 
    public function index() 
{ 
     //get the posted values 
    $data=$this->data; 
    $this->load->view('template',$data); 

} 
public function checklogin(){ 
    //form validation 
     $data=$this->data; 
     $this->form_validation->set_rules('username','Username','required'); 
     $this->form_validation->set_rules('password' ,'Password','required|callback_verifyUser'); 
      if($this->form_validation->run()==false){ 
      $this->load->view('template',$data); 
     } 
     else{ 

     } 
} 
public function verifyUser(){ 
    $name=$this->input->post('username'); 
    $pass=$this->input->post('password'); 
     $option=$this->input->post('optionlist'); 

    if($this->Login_model->login($name,$pass,$option)){ 
     return true; 

    }else{ 
        //user doesn't exist 
      //echo "Wrong username and password"; 
     $this->form_validation->set_message('verifyUser','Incorrect officer_id or password. Please try again'); 
     return false; 

    } 

} 
} 

?> 

是doen't顯示任何錯誤信息,用戶名是問題當我留下空白時,需要或密碼是必需的。它簡單地重新登錄到LOGIN_VIEW.PHP,而不顯示任何錯誤消息,即用戶名是空白的

該文檔所謂的形式驗證用於顯示錯誤。

的觀點login_view.php可以看出U形式在這裏http://pastebin.com/T2zMYGn1

+0

嗯......一切看起來OK我。你有什麼機會向我們展示template.php視圖文件? – Craig

+0

yeh sure template.php http://pastebin.com/850jTAc5 –

+0

你可以看看完整的代碼,如果你希望https://github.com/rachidasen/nic/tree/learnigniter –

回答

1

在視圖文件(template.php文件)使用echo validation_errors()要看到錯誤消息

+0

已經在視圖login_view中使用<?= validation_errors();?> –

+1

試試這個'template.php'文件,因爲我說,它會工作,因爲你的錯誤在那裏燒製 –

+0

謝謝它的工作。 –