php – 使用CodeIgniter表单验证的自定义错误消息
发布时间:2020-12-13 13:46:06 所属栏目:PHP教程 来源:网络整理
导读:我想在我的CodeIgniter表单中制作一些自定义错误消息.我试过用过 $this- form_validation- set_message(‘is_unique [users.username]’,’用户名已被占用’); 但是我无法让它发挥作用. 编辑form_validation_lang.php文件是不够的,因为is_unique将是已经为用
我想在我的CodeIgniter表单中制作一些自定义错误消息.我试过用过
$this-> form_validation-> set_message(‘is_unique [users.username]’,’用户名已被占用’); 但是我无法让它发挥作用. 编辑form_validation_lang.php文件是不够的,因为is_unique将是已经为用户名使用的用户名,并且已经为邮件注册了电子邮件. 如何制作此自定义错误消息? 这是我代码中的一个片段: $this->form_validation->set_message('is_unique[users.username]','The username is already taken'); // Check if username has changed if ($this->input->post('username') !== $user->username) { $this->form_validation->set_rules('username','Username','trim|required|min_length[4]|max_length[20]|is_unique[users.username]'); }
正确的方法是传递字符串格式
$this->form_validation->set_message('is_unique','The %s is already taken'); 那么,只有我们能够获得诸如“此用户名已被采用”或“此电子邮件已被采用”之类的消息. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |