[英]CodeIgniter Anonymous Form Validation
我有下面这样的代码:
$this->form_validation->set_rules("codetype", "Code Type", array(
"codecheck" => function ($str) {
// just return it false.
return false;
}
), array("codecheck"=>"return this message"));
我希望它返回codecheck错误消息。 但是codeigniter表单验证类返回此消息:
“无法访问与您的字段名称代码类型相对应的错误消息”。
如何编写带有错误消息的完全匿名的CodeIgniter函数?
希望这个能对您有所帮助 :
您可以required
删除required
,还可以设置if
条件
$this->form_validation->set_rules('codetype', 'Code Type',
array(
'required',
array(
'codecheck_callable',
function($str)
{
// Check validity of $str and return TRUE or FALSE
if ($str == 'test')
{
$this->form_validation->set_message('codecheck_callable', 'can not be test');
return false;
}
else
{
return TRUE;
}
}
)
)
);
有关更多信息: https : //www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods
根据CodeIgniter的文档, 网址为https://www.codeigniter.com/userguide3/libraries/form_validation.html
你可以这样
$this->form_validation->set_message('username_check', 'The {field} field can not be the word "test"');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.