CodeIgniter Forums
Unable to access an error message corresponding to your field name - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: Unable to access an error message corresponding to your field name (/showthread.php?tid=77515)



Unable to access an error message corresponding to your field name - Tryall34 - 09-10-2020

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;
        }
    }
}



RE: Unable to access an error message corresponding to your field name - Omar Crespo - 09-11-2020

Hello, there's no rule for the username. You must add one.