我正在尝试设置错误分隔符,效果很好。然而,有一个问题。所有错误的消息都会出现在顶部,这很好,但我希望所有问题都是这样的:
<div>
Username field too long
Password doesn't match
Please accept the terms
</div
不是这样的:
<div>Username field too long</div>
<div>Password doesn't match</div>
<div>Please accept the terms</div
屏幕截图:
不是这样的 http://gyazo.com/566c6752de463957fb39b103738d30cf
但是像这样 http://gyazo.com/47b284c5376a2ec94c560a697d3a1572
我的 View 文件中当前的代码(没有所有其他垃圾):
<?php echo validation_errors(); ?>
我的 Controller 代码:
public function user() {
$this->form_validation->set_rules('username', 'Username', 'required|trim|min_length[5]|max_length[25]|is_unique[users.username]|xss_clean');
//more rules but removed them just for the quesiton
if ($this->form_validation->run() == FALSE) {
$this->form_validation->set_error_delimiters(' <div class="alert alert-danger"><button class="close" data-dismiss="alert"></button>', '</div>');
$this->index();
}
}
非常感谢任何帮助。谢谢。
最佳答案
删除您在 Controller 中设置的错误分隔符并转到您的 View 文件,然后替换 <?php echo validation_errors(); ?>
与
<?php if (validation_errors()){
echo ' <div class="alert alert-danger"><button class="close" data-dismiss="alert"></button><b>You\'ve made some errors! Please check them below: <br></b>' ;
echo validation_errors();
echo '</div>';
}
?>
问题解决了!
关于php - Codeigniter - 更改错误分隔符 - 将所有错误放在一个 div 标签中,而不是单独的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29977543/