CodeIgniter $ this-> form_validation-> set_message

问题描述 投票:0回答:2

我做了一个电子邮件验证。

$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;
}

提交表单后,它显示“无法访问与您的字段名称对应的错误消息”。我的代码有问题吗?

php forms codeigniter validation
2个回答
5
投票

它应该是

$this->form_validation->set_message('email_check', 'Please provide an acceptable email address.');

4
投票

请参阅文档以供参考HERE

要设置自己的自定义消息,您可以使用以下功能:

$this->form_validation->set_message('rule', 'Error Message');

但你还没有在你的代码中正确命名规则它应该是email_check而不是email

$this->form_validation->set_message('email_check', 'Please provide an acceptable email address.');
© www.soinside.com 2019 - 2024. All rights reserved.