Php CodeIgniter匿名表单验证
我的代码如下所示:Php CodeIgniter匿名表单验证,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,我的代码如下所示: $this->form_validation->set_rules("codetype", "Code Type", array( "codecheck" => function ($str) { // just return it false. return false; } ), array("codecheck"=>"return this message")
$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函数?根据位于 你可以这样做
$this->form_validation->set_message('username_check', 'The {field} field can not be the word "test"');
希望这对您有所帮助: 如果需要,您可以删除
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;
}
}
)
)
);
更多信息:很抱歉,匿名函数也不能使用此功能。我还想要一个完全匿名的。它在codeigniter文档中也可用,但不起作用。然后尝试将最后一个参数从
数组(“codecheck”=>“return this message”)
更改为数组(“codetype”=>“return this message”)
如果验证是匿名的,则codeigniter表单验证自定义错误消息可能不会直接作用于set_rules函数。我的意思是关于set_规则的第三个参数。但这是可行的。谢谢