Welcome Guest, Not a member yet? Register   Sign In
Callbacks Not Working in Form Validation
#1

[eluser]Bl4cKWid0w[/eluser]
Hello. I am having some problems with the callback function in the form_validation class. I am trying to make a registration form for my clan's website. I thought it would be better to have only clan members be able to register, so I made a form that requires you put in the registration password before it takes you to the registration form. I have this form on the index. I looked over the code about 10 times and I just can't figure out what's wrong with it. My callback is like that of the one in the example in the userguide(you know, the example that says the inputted text can't be the word "test"), but I want it so that the input has to equal a certain password. This is the index function:
Code:
function index(){
        
        $this->load->model('constant');
        $this->constant->header();
        
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('regpass','Password','callback_verify_pass');
        $this->form_validation->set_error_delimiters('<li>','</li>');
        if ($this->form_validation->run() == FALSE){
            $this->load->view('register_pass');
        } else {
            redirect('register/info');
        }
        
        $this->load->view('overall_footer');
        
        function verify_pass($str){
            if($str != "shoelace"){
                $this->form_validation->set_message('verifypass','The password you entered was incorrect.');
                return FALSE;
            } else {
                return TRUE;
            }
            
        }
        
    }

I don't get any errors when I submit the form, however, but when I input random characters(e.g. asdfasdf), the form still submits and redirects me to the info function.

I just can't figure out what's wrong. Any help would be GREATLY appreciated. Watch it be something small that would take you 30 seconds to figure out.... LOL.
#2

[eluser]bitist[/eluser]
If I see well, your callback
Code:
function verify_pass($str)

is inside the index() function :-)

You should separate your functions:
Code:
function index() {
   //your code here
}

function verify_pass($str) {
   //your code here
}

In this way it must work.

Happy development!




Theme © iAndrew 2016 - Forum software by © MyBB