php CodeIgniter $this->form_validation->set_message
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19042180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CodeIgniter $this->form_validation->set_message
提问by Vincent
I have made an email validation.
我已经进行了电子邮件验证。
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email|callback_email_check');
function email_check($str)
{
if (stristr($str,'@uni-email-1.com') !== false) return true;
if (stristr($str,'@uni-email-2.com') !== false) return true;
if (stristr($str,'@uni-email-3.com') !== false) return true;
$this->form_validation->set_message('email', 'Please provide an acceptable email address.');
return FALSE;
}
After submitting my form, it says "Unable to access an error message corresponding to your field name." is there something wrong with my code?
提交我的表单后,它显示“无法访问与您的字段名称相对应的错误消息”。我的代码有问题吗?
回答by Fu Xu
it should be
它应该是
$this->form_validation->set_message('email_check', 'Please provide an acceptable email address.');
回答by Rajeev Ranjan
go to documentation for reference HERE
去文档参考HERE
To set your own custom message you can use the following function:
要设置您自己的自定义消息,您可以使用以下功能:
$this->form_validation->set_message('rule', 'Error Message');
but you haven't named the rule correctly in your code it should be email_check
instead of email
但是你有没有正确命名的规则在你的代码应该是email_check
代替email
$this->form_validation->set_message('email_check', 'Please provide an acceptable email address.');