【发布时间】:2016-02-18 12:38:18
【问题描述】:
Codeigniter 表单验证不显示错误 每当我在 codeigniter 中提交给定表单中的不完整字段时,它都不会显示任何错误,而是将我重定向到 about:blank 页面 查看:view/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');
}
}
}
?>
目前我不打算进行数据库验证,只检查所有字段是否已填写,如果是,则转到成功页面或在同一页面上显示验证错误!
【问题讨论】:
标签: php forms codeigniter