我在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 ISQUQUED或当我离开它时需要密码。它简单地重定向到LOGIN_VIEW.PHP,而不显示任何错误信息,因为用户名不为空白
文档中包含的表单验证用于显示错误。
对于查看login_view.php,您可以在此处查看表单http://pastebin.com/T2zMYGn1
答案 0 :(得分:1)
在要查看错误消息的视图文件(template.php)中使用echo validation_errors()