[eluser]Maximilian Schoening[/eluser]
Hi,
I have the following function inside a controller:
Code:
/** ----------------------------------------------------------------------
* User login
**/
function login() {
// if logged in
if ($this->session->userdata('logged_in')) {
redirect('/user', 'refresh');
}
// if logged out
else {
$this->load->helper('form');
$this->load->library('form_validation');
$validation_rules = array(
array(
'field' => 'email',
'label' => 'Email',
'rules' => 'required|validemail'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'requied|callback_authenticate'
)
);
// validate password
function authenticate() {
$this->load->library('authentication');
if ( ! $this->authentication->login($this->input->post('email'), $this->input->post('password'))) {
return FALSE;
}
else {
return TRUE;
}
}
$this->form_validation->set_rules($validation_rules);
if ($this->form_validation->run() == false) {
$this->load->view('user/login');
}
else {
redirect('/user', 'refresh');
}
}
}
// -----------------------------------------------------------------------
As you can see I am validating the password field with a custom validation function (authenticate()) but all this function does is call another function inside a library. Can I load the library function login() directly into the validation rules?
Thanks,
Max