I have a problem in my code. I am creating a simple login using CI3 for my small project. My problem is I have an error message in callback validation.
Here's the error I received whenever I try to validate my form.
Unable to access an error message corresponding to your field name Password.(check_database)
Here's mo code in controller:
public function index() {
$this->form_validation->set_rules('username', 'Username', 'trim|required');
$this->form_validation->set_rules('password', 'Password', 'trim|required|callback_check_database');
$this->form_validation->set_error_delimiters('<div class="error text-red">', '</div>');
if($this->form_validation->run() == FALSE) {
$data = array();
$data['modules'] = $this->flx_lib->moduler($data);
$this->load->view('login', $data);
} else {
//ok
}
}
public function check_database($password) {
$username = $this->input->post($username);
$result = $this->flx_users->validate_user($username, $password);
if($result) {
//ok
return TRUE;
} else {
$this->form_validation->set_message('check_database', 'Invalid username or password');
return FALSE;
}
}
Here's my view:
<div class="form-group has-feedback <?php error_exists('username'); ?>">
<input type="text" class="form-control" name="username" placeholder="Username" />
<span class="fa fa-user form-control-feedback "></span>
<?php echo form_error('username'); ?>
</div>
<div class="form-group has-feedback <?php error_exists('password'); ?>">
<input type="password" class="form-control" name="password" placeholder="Password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
<?php echo form_error('password'); ?>
</div>
Can you help me with this? I am using CI3 with HMVC