我的表单验证错误已停止工作,昨天正常工作,我一定做错了什么但似乎无法找到它。
当我点击注册而不填写任何信息时,它只会重定向到加载视图的admin_login.php。
admin_login.php //控制器文件
<?php
//session_start();
defined('BASEPATH') OR exit('No direct script access allowed');
class Admin_login extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->helper('url');
$this->load->library('session');
$this->load->model('loginModel');
}
public function index()
{
$this->load->view('admin_view');
}
public function login()
{
// Load session library
$this->load->library('form_validation');
$this->form_validation->set_rules('admin', 'user_name', 'required|alpha');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE)
{
return redirect('admin_login');
//$this->load->view('admin_view');
}
else
{
//echo "successful validation <br>";
$admin = $this->input->post('admin');
$password = $this->input->post('password');
$login_id = $this->loginModel->admin_login($admin, $password);
if($login_id)
{
echo "valid admin_name and user <br>";
//$this->session->set_userdata('id', $login_id);
//return redirect('listing');
$this->load->view('listing');
}
else
{
//$this->session->set_flashdata('flashError','invalid user_name/password');
redirect('admin_login');
echo "wrong admin_name or password";
}
}
}
}
admin_view.php //查看文件
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<title>first tutoial</title>
</head>
<body>
<div id="container">
<h1>Welcome to Admin Login</h1>
<!-- new line inserted -->
<?php echo form_open('admin_login/login'); ?>
Admin User_Name: <input type="text" name="admin" class="text-denger"value="" placeholder="admin name" >
<?php echo form_error("admin"); ?>
<br>
Admin Password: <input type="password" name="password" value="" placeholder="password" >
<?php echo form_error("password"); ?>
<br>
<br>
<input type="submit" name="submit" value="submit" id="">
</form>
</div>
</body>
</html>
答案 0 :(得分:0)
将此更改为
<?php echo form_open('admin_login/login'); ?>
到
<?php echo form_open('Admin_login/login'); ?>
您的班级名称是 Admin_login ,但您尝试打开 admin_login 类
答案 1 :(得分:0)
始终使用$ this-&gt; load-&gt; view(); 而是redirect();功能。 重定向功能不会显示任何验证错误消息。