Im a beginner in web programming, so please bear with me.
I tried to create a login system that will do those validation :
- The email is required and must be valid
- The password is required
- If the login failed, i will create a span for the user
I can accomplish the 1st & 2nd easily using codeigniter's form validation. However, the 3rd is not that easy because i need to check it first from the DB.
So i tried to create a code like this :
function login() {
$data['validation'] = TRUE;
$this->form_validation->set_rules('txt_email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('txt_password', 'Password', 'required');
if($this->form_validation->run() !== FALSE)
{
$log_in = $this->umat_m->log_in($this->input->post('txt_email'), $this->input->post('txt_password'));
if($log_in !== FALSE)
{
$data['validation'] = TRUE;
$_SESSION['username'] = $this->input->post('txt_email');
redirect('backend/umat/index');
}
else
$data['validation'] = FALSE;
}
$this->load->view('backend/login_v', $data);
}
And the HTML :
<?php echo form_submit('btn_submit', 'Log In', 'class = "btn btn-primary"'); ?> <br/>
<?php
if($validation === FALSE)
echo '<span class="label label-important">Wrong Username/Password</span>';
else
echo '<span class="label label-important"><?php echo validation_errors(); ?></span>';
?>
What i tried to do is if the user already fill the Email & Password field but the value is wrong then i will echo the first span.
However, this code is still not working. When the user fill the wrong value (but not empty), the Wrong Username/Password span is echoed but when the textfield is empty, the codeigniter's form validation dont show any message (that means the 2nd echo is never showed).
Any help is appreciated, and please just ask me if you need something more.