Vin*_*ent 0 php forms validation codeigniter
我做了一个电子邮件验证.
$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;
}
Run Code Online (Sandbox Code Playgroud)
提交表单后,它显示"无法访问与您的字段名称对应的错误消息".我的代码有问题吗?
小智 5
它应该是
$this->form_validation->set_message('email_check', 'Please provide an acceptable email address.');
Run Code Online (Sandbox Code Playgroud)
去文档参考HERE
要设置您自己的自定义消息,您可以使用以下功能:
$this->form_validation->set_message('rule', 'Error Message');
Run Code Online (Sandbox Code Playgroud)
但是你有没有正确命名的规则在你的代码应该是email_check代替email
$this->form_validation->set_message('email_check', 'Please provide an acceptable email address.');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22104 次 |
| 最近记录: |