Codeigniter表单验证不显示错误 每当我在codeigniter中提交给定表单中的不完整字段时,它都不会显示任何错误,而是将我重定向到about:blank page 视图:图/ forms.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="password" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="password" name="passconf" value="" size="50" />
<h5>Email Address</h5>
<input type="email" name="email" value="" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
</body>
</html>
控制器:
<?php
class Form extends CI_Controller {
function index()
{
/*Load the form validation helpers*/
$this->load->helper(array('form', 'url'));
/*Load the form validation helpers*/
$this->load->library('form_validation');
/*Set the form validation rules*/
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
/*Check if the form passed its validation */
if ($this->form_validation->run() == FALSE) {
$this->load->view('forms');
}
else {
$this->load->view('formsuccess');
}
}
}
?>
目前我不打算进行数据库验证,只检查是否填写了所有字段,如果是,请转到成功页面或在同一页面上显示验证错误!
答案 0 :(得分:0)
尝试在视图中添加required
<input type="text" name="username" value="" size="50" required/>
<h5>Password</h5>
<input type="password" name="password" value="" size="50" required/>
<h5>Password Confirm</h5>
<input type="password" name="passconf" value="" size="50" required/>
<h5>Email Address</h5>
<input type="email" name="email" value="" size="50" required/>
控制器 -
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
}
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
检查您的.htaccess文件
答案 1 :(得分:0)
认为我的xampp存在问题,因为我将文件夹转移到了我的其他笔记本电脑,它在那里工作得很好!!将尝试重新安装xampp