[eluser]balboa_1990[/eluser]
I have set up a registration/login area and validated everything (including empty fields) and hit a wall when displaying an error message if the username and/or password are incorrect. At the moment, i can get an error message to display if the fields are left blank but on submit the page redirects to the 'private page' either with correct or incorrect user details. This is my current code:
Controller:
Code:
<? if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$data['main_content'] = 'login';
$this->load->view('include/template', $data);
}
//Validate login area
//This method will have the credentials validation
public function validate() {
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
if($this->form_validation->run() == FALSE)
{
//Field validation failed. User redirected to login page
$this->index();
}else{
//Go to private area
redirect('admin/news', 'refresh');
}
}
//Validate signup area
public function signup() {
$data['main_content'] = 'signup';
$this->load->view('include/template', $data);
}
public function create_member() {
$this->load->library('form_validation');
//field name, error, message, validation rules
$this->form_validation->set_rules('first_name', 'Name', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
$this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('password2', 'Password Confirm', 'trim|required|matches[password]');
if($this->form_validation->run() == FALSE) {
$this->signup();
}else{
$this->load->model('register_model');
if($query = $this->register_model->create_membership()) {
$data['main_content'] = 'signup_successful';
$this->load->view('include/template', $data);
}else {
$this->load->view('signup');
}
}
}
}
Any opinion, methods, links would be appreciated.