[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.