Created my own library to add new users. Configured autoloading for
form_validation and
check, new_data models. When submitting a form at the place where errors should be displayed (if any), output:
Unable to access an error message corresponding to your field name Username. (Is_username_exist) is displayed. How do I get the correct error message to appear?
Code:
class Register
{
private $CI;
public function add_new_user()
{
$CI =& get_instance();
$CI->form_validation->set_rules('email', 'Email', 'required|callback_is_email_exist');
if ($CI->form_validation->run() == TRUE)
{
$email = $_POST['email'];
$insert_data = array('email' => $email);
$CI->new_data->add_user($insert_data);
}
}
private function is_email_exist($email)
{
$CI =& get_instance();
$email_result = '';
$query = $CI->check->find_email($email);
foreach ($query->result_array() as $row)
{
$email_result = $row['email'];
}
if ($email_result == $email)
{
$CI->form_validation->set_message('is_email_exist', 'Such email already exist!');
return FALSE;
}
else
{
return TRUE;
}
}
}