Hi guys i have simple captcha that seems to working but the only problem i have seems to be with the callback function on the validation have a look at the captcha:

    function index()
    {
        $this->load->helper('captcha');
        $this->load->library('form_validation');
        //Input field, Friendly name, Attributes
        $this->form_validation->set_rules('name', 'Name', 'trim|required');
        $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
        $this->form_validation->set_rules('number', 'Contact Number', 'trim|required|numeric');
        $this->form_validation->set_rules('userCaptcha', 'Captcha', 'required|callback_check_captcha');

        $userCaptcha = $this->input->post('userCaptcha');

        //Check the fields for Validation Errors
        if ($this->form_validation->run() == FALSE) {

            $random_number = substr(number_format(time() * rand(),0,'',''),0,6);
            $values = array(
                'word' => $random_number,
                'img_path' => './captcha/',
                'img_url' => base_url().'captcha/',
                'img_width' => 140,
                'img_height' => 32,
                'expiration' => 7200
            );

            $data['captcha'] = create_captcha($values);
            $this->session->set_userdata('captchaWord',$data['captcha']['word']);

            //Load the view variables
            $data['today'] = date('l, d F Y');
            $data['title'] = "Contact Us";
            $data['content'] = 'site/contact_view';
            $this->load->view('templates/site/template', $data);
            }

that all works fine the captcha genrates and displays nicely on the form but when i try and test the captcha it returns a error on my callback:

    function check_captcha($str){
        $word = $this->session->userdata('captchaWord');
        if(strcmp(strtoupper($str),strtoupper($word)) == 0){
            return true;
        }
        else{
            $this->form_validation->set_message('userCaptcha', 'Your code did not match!');
            return false;
        }
    }

keep getting the following error when the form runs:

Unable to access an error message corresponding to your field name Captcha.(check_captcha)

Where am i going wrong?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.