Reputation: 327
Issue 1) 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:
Issue 1 (RESOLVED):
Controller:
//This method will have the credentials validation
public function credentials_validation() {
$data['error'] ="Invalid Username or Password";
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback_username_check');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_password_check');
if($this->form_validation->run() == FALSE)
{
//Field validation failed. User redirected to login page
$this->index();
}else{
$this->load->model('register_model');
if($query = $this->register_model->validate()) {
$this->load->model('news_model');
$data = array('news' => $this->news_model->getArticle());
$data['title'] = 'Admin | Home';
$data['heading'] = 'News Articles';
$data['main_content'] = 'admin/news';
$this->load->view('include/template', $data);
}else {
$this->load->view('login',$data);
}
}
}
Issue 2) News Article Page only loads 1 article and url displays class name.
News Controller:
class News extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('admin/news_model');
}
public function index() {
$data = array('news' => $this->news_model->getArticle());
$data['title'] = 'Admin | News Home';
$data['heading'] = 'News Articles';
$this->load->view('admin/news', $data);
}
}
The news model is just pulling the database table, select all and order by id and resulting in the array. Anyone have any ideas why this is only displaying 1 result? I think its something to do with the foreach method?
PS, No error messages displayed from CI or php error log!
Upvotes: 1
Views: 11986
Reputation: 795
The best way would be to store the error messages in an array e.g.
$data['error'] ="Invalid Login";
For example in the controller
if($query = $this->register_model->check_membership()) {
$data['main_content'] = 'signup_successful';
$this->load->view('include/template', $data);
}else {
$data["error"]="Invalid User Id and Password combination";
$this->load->view('signup',$data);
}
The check_membership
function should check whether the login id and password combination are ok or not.
And then in the signup
view page, put something at the top like
if (isset($error)){
echo "<div class='error'>$error</div>";
}
Upvotes: 6