CodeIgniter Forums

Full Version: My validation callback isn't getting called. :(
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Kinsbane[/eluser]
I have a function that registers a user. The function when run needs to check the $_POST data and make sure the chosen username and email address are not dupes.

The user_duplicate_check callback gets called just fine, and works as it should.
However, if I input a unique username, but use a previously used email address, the form goes through and I get the registration email.

I looked in the logs for any troubleshooting help, but there was none. I put a die() message in the email_duplicate_check function before it ever did anything, just to see if it gets called, and it doesn't.

What's the best way to see that a callback function gets called? Can I only use one callback function when validating form data?

I'd post code, but I don't know which code to post, heh!

El Forum

[eluser]Bogdan Tanase[/eluser]
the callback function doesn't get called if your field that doesn't have "required" set and the field is submitted blank.

I don't know if this is your case though...

El Forum

[eluser]Sumon[/eluser]
Paste your call back function as well as the line where you call that function.

El Forum

[eluser]Kinsbane[/eluser]
[quote author="Bogdan Tanase" date="1222821631"]the callback function doesn't get called if your field that doesn't have "required" set and the field is submitted blank.

I don't know if this is your case though...[/quote]

Yeah, having an email is required to create a user. So, it is set. But if it wasn't, then it would still call the function if there was a value in there, right? It's not doing that.

El Forum

[eluser]Kinsbane[/eluser]
[quote author="Sumon" date="1222822054"]Paste your call back function as well as the line where you call that function.[/quote]

Here's the register function:
Code:
function register()
    {
        $rules[$this->config->item('auth_user_name_field')] = $this->config->item('auth_user_name_field_validation_register');
        $rules[$this->config->item('auth_user_password_confirm_field')] = $this->config->item('auth_password_required_confirm_validation')."|matches[".$this->config->item('auth_user_password_field')."]";
        $rules[$this->config->item('auth_user_password_field')] = $this->config->item('auth_user_password_field_validation_register');
        $rules['email'] = 'trim|required|valid_email|xss_clean|callback_email_dupliate_check';
        
        if ($this->config->item('auth_use_country'))
            $rules[$this->config->item('auth_user_country_field')] = $this->config->item('auth_user_country_field_validation_register');
        
        //additionalRegistrationRules($rules);
        
        $this->validation->set_rules($rules);
        
        if ($this->validation->run() && $this->authlib->register())
        {
            $this->load->view($this->config->item('auth_register_success_view'));
            $this->output->enable_profiler(TRUE);
        }
        else
        {
            $this->db_session->flashdata_mark();
            $this->register_index();
        }
    }

Here's the callback function:
Code:
function email_duplicate_check($value)
    {
        die('Is this callback even getting called?');
        $this->obj->db->where('email', $value);
        $query = $this->obj->db->get($this->obj->config->item('auth_user_table_name'));
        
        if (($query != null) && ($query->num_rows() > 0))
        {
            $this->validation->set_message('email_duplicate_check', 'The email address <strong>'.$value.'</strong> is already in use.');
            return false;
        }
        
        return true;
    }

The email_duplicate_check is the exact same function as the one that checks for dupe usernames, and that callback function works. This one, though, never even gets called.

If you're wondering about the $this->register_index(), the controller is working as it should, as the register_index() function just displays the view file. When the validation fails, all appropriate error messages get displayed, no problem.

El Forum

[eluser]Bogdan Tanase[/eluser]
hmm.. it seems you have a typo here:

Code:
$rules['email'] = 'trim|required|valid_email|xss_clean|callback_email_dupliate_check';

El Forum

[eluser]Kinsbane[/eluser]
That would be it! Thanks Bogdan!