我是codeigniter developpement的新手。我创建了简单的登录表单,如下所示:
在我的login_view页面
<?php echo validation_errors(); ?>
//my form html code comes here
在我的控制器页面
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('login_view',$data);
}
else
{
//form validated do some work here
}
现在的问题是,当我提交带有空用户名和密码字段的表单时,这会显示错误为
The Username field is required.
The Password field is required.
这是对的,但我想只显示单个消息
Please enter username and password......
而不是每个字段有两个或N个消息。我已经尝试过form_error('fieldname')函数但没有用。我如何获得上述输出。
提前致谢。
答案 0 :(得分:1)
在视图中,您可以使用:
<?php if (form_error('username') || form_error('password')): ?>
<div class="error">Please enter username and password......</div>
<?php endif; ?>