I have a problem, my codeigniter is not displaying error messages.
When I do a var_dump
on $this->form_validation->run()
, it returns true if everything is completed and false if not.
Here is the code:
Controller
defined('BASEPATH') OR exit('No direct script access allowed');
class Logon extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('logon_model', 'logon');
}
public function autenthicate() {
$this->form_validation->set_rules('usuario', 'Usuario', 'required');
$this->form_validation->set_rules('senha', 'Senha', 'required');
if ($this->form_validation->run() == TRUE):
#Array with data
$data = elements(array('user', 'password'), $this->input->post());
$data['password'] = md5($data['password']);
#Send data to model
if ($this->logon->do_login($data)->result()):
$data = $this->logon->do_login($data)->result();
$user_data = array(
'id' => $data['id'],
'name' => $data['name'],
'logged' => TRUE
);
$this->session->set_userdata($user_data);
redirect('sales');
$this->session->set_flashdata('loginerror', 'Login failed! User or password is invalid.');
redirect('logon');
endif;
else:
$data = array(
'title' => 'Logon',
'screen' => 'index',
);
$this->load->view('index_view', $dados);
endif;
}
}
View
<?php
echo form_open('logon/autenthicate');
echo '<div class="form-group">';
echo form_label("User");
echo form_input(array('name' => 'user', 'class' => 'form-control'));
echo '</div>';
echo '<div class="form-group">';
echo form_label("passwor");
echo form_password(array('name' => 'password', 'class' => 'form-control'));
echo '</div>';
echo '<div class="form-group">';
echo form_submit('logon', 'Logon', 'class="btn btn-default btn-block"');
echo '</div>';
#Show a alert div with validation errors
echo validation_errors('<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>', '</div>');
echo form_close();
?>
Apparently it's all right, but I can not find the error. If the form is completed and the registered user, it will be redirected to the home page, if not back to the login screen, but without displaying the error.
Can you help me?