I'm using a form_validation
in my CI application and while using a callback function
in set_rules()
I got an error:
Unable to access an error message corresponding to your field name Email.(validate_credentials)
My Controller code is:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Auth extends MX_Controller
{
// public function __construct()
// {
// parent::__construct();
// }
// public function index()
// {
// $this->load->view('auth/login_v');
// }
public function login()
{
$this->load->view('auth/login_v');
}
public function login_validation()
{
//$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|trim|callback_validate_credentials');
$this->form_validation->set_rules('password', 'Password', 'required|md5|trim');
if($this->form_validation->run())
{
redirect('dashboard');
} else {
$this->load->view('auth/login_v');
}
//echo $this->input->post('email');
}
public function validate_credentials()
{
$this->load->model('Auth_model');
if($this->Auth_model->can_log_in())
{
return true;
} else {
$this->form_validation->set_message('validate_credentials', 'Incorrect Email/Password');
return false;
}
}
}
I don't know where am I mistaking. I had pass the parameters to tha callback function:
$this->form_validation->set_rules('email', 'Email', 'required|trim|callback_validate_credentials[email]');
and
public function validate_credentials($email)
{
$this->load->model('Auth_model');
but I got same error.
I have referred following sites:
In Codeigniter, how to pass a third parameter to a callback (form validation)?
Unable to access an error message corresponding to your field name
Callback function in Codeigniter with multiple parameters during form validation
CodeIgniter callback functions with parameters
Callback Function Error ( Unable to access an error message corresponding to your field name )
I'm using codeigniter 3.1.6 and HMVC for my application.
Any kind of help will always welcome. Thanks