1

我在 autoload.php 中有自动加载辅助表单和库表单验证

 <?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;

    }

 }
}

?>

问题是它没有显示任何错误消息 USERNAME IS REQUIRED OR PASSWORD IS REQUIRED WHEN I LEAVE IT BLANK 。它只是重定向到 LOGIN_VIEW.PHP 而不显示任何错误消息,即用户名留空

文档说表单验证用于显示错误的目的。

对于视图 login_view.php,您可以在此处查看表单 http://pastebin.com/T2zMYGn1

4

1 回答 1

1

echo validation_errors()在要查看错误消息的视图文件 (template.php) 中使用

于 2015-06-18T10:16:01.010 回答