Welcome Guest, Not a member yet? Register   Sign In
Call Back Function Issue
#1

[eluser]everythingevolves[/eluser]
Hi,

I'm still quite new to code ignitor but am giving it a good go. Today I have been looking at the form_helper/validation but seem to be having an issue with the callback function. I've tried a number of different options but don't seem to be getting anywhere. The controller file is listed below:

Code:
<?php

class Register extends Controller
    {
        function Register()
            {
            parent:: Controller();
            
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
            }
        
    
        function index()
            {
            $this->form_validation->set_rules('forename', 'Forename', 'trim|required|alpha_dash');
            $this->form_validation->set_rules('surname', 'Surname', 'trim|required|alpha_dash');
            $this->form_validation->set_rules('email_login', 'Email login', 'trim|valid_email|required|callback_email_login_check');
            $this->form_validation->set_rules('password', 'Password', 'trim|required|alpha_numeric|min_length[5]|max_length[12]|matches[passconf]|md5');
            $this->form_validation->set_rules('passconf', 'Confirm Password', 'trim|required');
            
            if ($this->form_validation->run() == FALSE)
                {
                $title['page_title'] = "Registration Form";
                
                $this->load->view('header', $title);
                $this->load->view('menu');
                $this->load->view('register');
                $this->load->view('related_links');
                $this->load->view('footer');
                }
            else
                {
                $data = array(
                           'forename' => $_POST['forename'],
                           'surname' => $_POST['surname'],
                        'email_login' => $_POST['email_login'],
                        'password' => $_POST['password'],
                        );
            
                $this->db->insert('users', $data);
                
                $title['page_title'] = "Registration successful!";
                $title['page_heading'] = "Your Registration was successful!";
                
                $this->load->view('header', $title);
                $this->load->view('menu');
                $this->load->view('action_successful', $title);
                $this->load->view('related_links');
                $this->load->view('footer');
                }
            }
        
        function email_login_check($email_login)
            {
            $query = $this->db->query("SELECT * FROM users WHERE email_login='$email_login'");
            
            if ($query->num_rows() > 0)
                {
                $this->form_validation->set_message('email_login_check', 'The %s "$email_login" already exists.');
                return FALSE;
                }
            else
                {
                return TRUE;
                }
            }
    }


/* End of file register.php */
/* Location: ./system/application/controllers/register.php */

When the call back is called to check that the email_login doesn't already exist in the users table of my database, I seem to keep getting this message where the error message is displayed in my view:

"Unable to access an error message corresponding to your field name."

No doubt it's something stupid that I've overlooked and I'll continue to keep trying, but if anyone can see what's wrong then it would be greatly appreciated.

All the best.


Messages In This Thread
Call Back Function Issue - by El Forum - 02-25-2009, 05:35 PM
Call Back Function Issue - by El Forum - 02-25-2009, 06:23 PM
Call Back Function Issue - by El Forum - 02-26-2009, 12:26 PM
Call Back Function Issue - by El Forum - 02-26-2009, 01:28 PM
Call Back Function Issue - by El Forum - 02-26-2009, 02:01 PM
Call Back Function Issue - by El Forum - 02-26-2009, 03:23 PM
Call Back Function Issue - by El Forum - 02-26-2009, 03:45 PM
Call Back Function Issue - by El Forum - 02-26-2009, 03:46 PM
Call Back Function Issue - by El Forum - 02-26-2009, 03:51 PM
Call Back Function Issue - by El Forum - 02-26-2009, 03:55 PM
Call Back Function Issue - by El Forum - 02-26-2009, 05:29 PM
Call Back Function Issue - by El Forum - 04-10-2009, 07:59 PM
Call Back Function Issue - by El Forum - 05-14-2009, 02:54 PM
Call Back Function Issue - by El Forum - 07-21-2009, 08:26 AM
Call Back Function Issue - by El Forum - 08-24-2009, 12:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB