如何在代码点火器中给出逗号错误消息而不是多个错误



我是代码点火器开发的新手。我创建了简单的登录表单,如下所示:

在我的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("字段名称")函数但没有用。我如何获得上述输出。

提前谢谢。

在视图中,您可以使用:

<?php if (form_error('username') || form_error('password')): ?>
  <div class="error">Please enter username and password......</div>
<?php endif; ?>

相关内容

最新更新