我目前正在尝试找到一种只显示错误列表的特定错误的方法。
$this->form_validation->set_rules('password', 'lang:user.password', 'trim|required|min_length[6]|max_length[12]|matches[password_confirm]');
如果字段为空,我希望能够显示消息,例如“某些字段缺失”。但是我想显示一条特定的消息,如果用户只写了一个短于6个字符或大于12的密码,如“密码长度必须在6到12个字符之间”
THX。
答案 0 :(得分:4)
我鼓励您阅读documentation。你可以:
使用以下命令动态设置错误消息:
$this->form_validation->set_message('required', '%s must not be empty.');
$this->form_validation->set_message('min_length', '%s must be between 6 and 12 characters.');
$this->form_validation->set_message('max_length', '%s must be between 6 and 12 characters.');
答案 1 :(得分:0)
一旦设定了规则,您只需确保包含
<?php echo validation_errors(); ?>
在你的形式的某个地方。
您还可以使用以下内容显示个别错误: -
<?php echo form_error('password'); ?>
此处有更多信息: - Form Validation : CodeIgniter User Guide