Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带CodeIgniter的Recaptcha_Codeigniter_Recaptcha - Fatal编程技术网

带CodeIgniter的Recaptcha

带CodeIgniter的Recaptcha,codeigniter,recaptcha,Codeigniter,Recaptcha,我正在尝试在CodeIgniter中实现recaptcha我的表单(不使用recaptcha库)。这很好,但是在我的表单中,我单独显示每个字段的错误,我想在表单中的位置旁边显示recaptcha错误,有人能帮我怎么做吗 来自我的控制器的代码: $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[3]|max_length[25]'); $this->form_va

我正在尝试在CodeIgniter中实现recaptcha我的表单(不使用recaptcha库)。这很好,但是在我的表单中,我单独显示每个字段的错误,我想在表单中的位置旁边显示recaptcha错误,有人能帮我怎么做吗

来自我的控制器的代码:

    $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[3]|max_length[25]');
    $this->form_validation->set_rules('email', 'Email address', 'trim|required|valid_email');   

    //With above set_rules i'm able to display each fields errors next to it, 
    //How can i display following recaptcha error next to it.
        if (!$resp->is_valid)
        {
            //reCAPTCHA was entered incorrectly
            die (
            "The reCAPTCHA wasn entered incorrectly." .
            "(reCAPTCHA said: " . $resp->error . ")
            ");
        }
        else
        {
            //Successful verification
            die('Success!');
        }

感谢您的帮助。

如果您没有通过表单验证库运行recaptcha字段,您将无法使用
表单错误()
函数,但您可以轻松地将错误作为变量发送到视图:

if ($this->form_validation->run())
{
    if ( ! $resp->is_valid)
    {
        $data['recaptcha_error'] = "reCAPTCHA said: ".$resp->error;
    }
    else
    {
        // Process form
    }
}
$this->load->view('my_view', $data);
然后在您看来(无论您想在哪里/以何种方式):


<?php if (isset($recaptcha_error)): ?>
    <label class="error">
        <?php echo $recaptcha_error; ?>
    </label>
<?php endif; ?>