Welcome Guest, Not a member yet? Register   Sign In
Problems with Callback Functions and Validation Class
#9

[eluser]mariowarner[/eluser]
Thanks, man!

It still won't work so I did a different hack.

I retained the original format of the callback function because it works on my local machine (in case the issue is not with CI but on the server configurations:
Code:
function cinputCheck($str)
    {
        if ($str != $_SESSION["pass"])  {
            $this->validation->set_message('cinputCheck', 'Incorrect Captcha characters.');
            return FALSE;                            
        }
        else
        {
            return TRUE;        
        }
    }

And then I did a string search for the error message generated by Validation Class in case it can't find an error message (this only works well with my codes because I know for sure that there's only one error that generates that error message):
Code:
// set validation rules
        $rules['cinput'] = "required|callback_cinput_check";
        $rules['email1']     = "required|valid_email";
        $rules['email2']     = "required|valid_email|matches[email1]";        

        $this->validation->set_rules($rules);
        
        if ($this->validation->run() == FALSE) {
            $data['success'] = "0";
            
            if($this->validation->error_string) {
                $data['message'] .= '<br />Error(s): ';
            }
                    
            $data['message'] .= $this->validation->error_string;
            
            $reg_ex = 'Unable to access an error message corresponding to your field name.';
            $str = $data['message'];
            
            // i only used this because i know for sure that the $reg_ex message only shows up
            // when i get to the Captcha callback function.
            if (strpos($str, $reg_ex) !== false) {
               $data['message'] = str_replace('Unable to access an error message
                                       corresponding to your field name.',
                    'The characters you typed did not match the characters on the box.', $str);
            }
            
            $this->load->view('prelaunch', $data);
        }
        
        else {
                         // no more errors, proceed with the success methods
                }

Again, it might not work well with bigger forms with more than one callback function (cos i think the error has to do with Validation Class' callback functions), but it did the trick for now.


Messages In This Thread
Problems with Callback Functions and Validation Class - by El Forum - 03-16-2008, 04:18 PM
Problems with Callback Functions and Validation Class - by El Forum - 03-16-2008, 08:22 PM
Problems with Callback Functions and Validation Class - by El Forum - 03-16-2008, 09:57 PM
Problems with Callback Functions and Validation Class - by El Forum - 03-16-2008, 10:16 PM
Problems with Callback Functions and Validation Class - by El Forum - 03-17-2008, 12:00 PM
Problems with Callback Functions and Validation Class - by El Forum - 03-17-2008, 01:31 PM
Problems with Callback Functions and Validation Class - by El Forum - 03-17-2008, 01:34 PM
Problems with Callback Functions and Validation Class - by El Forum - 03-18-2008, 04:46 AM
Problems with Callback Functions and Validation Class - by El Forum - 03-18-2008, 03:50 PM
Problems with Callback Functions and Validation Class - by El Forum - 04-14-2008, 03:40 PM
Problems with Callback Functions and Validation Class - by El Forum - 04-14-2008, 07:39 PM
Problems with Callback Functions and Validation Class - by El Forum - 06-16-2008, 09:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB