[eluser]merik[/eluser]
I am using form validation to show warning messages to the user when the username and password doesn't meet the required validation rules:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Adminlogin extends CI_Controller {
function __construct()
{
parent::__construct();
session_start();
}
public function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username',
'required|validemail');
$this->form_validation->set_rules('password', 'Password',
'required|min_length[4]');
if ($this->form_validation->run() !== false) {
$this->load->model('adminauth');
$auth = $this->adminauth->authenticate(
$this->input->post('username'),
$this->input->post('password'));
if ($auth !== false) {
$_SESSION['username'] = $this->input->post('username');
redirect('admin');
} else {
# ...
}
}
$this->load->view('login');
}
}
This way, if the username is missing or password is too short, I show a warning message above the form:
Code:
<?php echo validation_errors('<div class="alert alert-error">','</div>'); ?>
I was wondering if I could also throw a validation error when the username and password passes the rules, but don't match any record in the database. I can do it manually (by creating another DIV like the last one, and showing a message in it, when authentication fails), but I wonder if I can reuse the
validation_errors() function for that.
I thought of using callback functions, but they are only for single input fields, not a combination of username and password. Any idea?