使用orm和外部captcha规则进行Kohana表单验证



我正在尝试为captcha添加外部验证规则,如下所示:

$extra_rules = Validation::factory($_POST)
                    ->rule('captcha',  array(Captcha::valid($_POST['captcha'])));

我认为有效的功能正在运行,但后来我得到了这个错误:

ErrorException [ Notice ]: Undefined offset: 1
SYSPATH/classes/Kohana/Validation.php [ 376 ]
371                     // Replace with bound value
372                     $rule[0] = $this->_bound[$rule[0]];
373                     }
374 
375                     // This is an array callback, the method name is the error name
376                     $error_name = $rule[1];
377                     $passed = call_user_func_array($rule, $params);

请帮忙。我不知道如何管理这个captcha验证

看起来你没有正确定义验证规则,试试这个:

$extra_rules = Validation::factory($this->request->post())
                ->rule('captcha',  'Captcha::valid'));

此外,由于Kohana v3.+HMVC的功能,不鼓励使用$_POST超全局,建议使用$this->request->post()

最新更新