2013-06-26 18 views
0

我想添加外部验证规则的验证码这样的Kohana表单验证:与ORM和外部的验证码规则

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

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

回答

1

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

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

同时,由于Kohana的V3的+ HMVC功能,使用$_POST超全球化是不鼓励的,并且使用是推荐的做法。

+0

This works。谢谢。但我不明白这个答案的$ _POST部分。这是否意味着我应该使用$ this-> request-> post()来获取表单的值?比如说,我用$ this-> request-> post()获得$ _POST ['email']? – masteryoda

+0

$ _POST ['email']将作为$ this-> request-> post('email')进行访问。如果键不存在$ this-> request-> post()将返回NULL。 http://kohanaframework.org/3.3/guide-api/Request#post – Dickie