【问题标题】:Kohana form validation with orm and external captcha rule使用 orm 和外部验证码规则进行 Kohana 表单验证
【发布时间】:2013-06-26 08:19:29
【问题描述】:

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

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

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

【问题讨论】:

    标签: validation orm kohana external captcha


    【解决方案1】:

    您似乎没有正确定义验证规则,试试这个:

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

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

    【讨论】:

    • 这行得通。谢谢你。但我不明白答案的这个 $_POST 部分。这是否意味着我应该使用 $this->request->post() 来获取表单的值?例如,我应该如何使用 $this->request->post() 获得 $_POST['email']?
    • $_POST['email'] 将作为 $this->request->post('email') 访问。如果键不存在 $this->request->post() 将返回 NULL。 kohanaframework.org/3.3/guide-api/Request#post
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    • 2012-02-25
    • 2014-04-21
    相关资源
    最近更新 更多