I am really close to giving up on the native form validation error functions in Code Igniter as I am having great trouble getting them to work properly. My logic seems straight as an arrow, however the behavior of the error posing is really throwing me for a loop based off of my logic.
so here is a list of what is going on.
*When I submit the form without filling out any fields = the invalid email and password errors pose as they should
*When I enter the CORRECT email and leave password field blank = the proper invalid password error poses as it should
*When I enter the correct email and an incorrect password = the page loads white
*When I enter just the password field = the invalid email comes up
*When I enter gibberish email and leave password blank = invalid email comes up
There are many combinations of false hood that are going on.
I am also wanting to make the emails unique to where it recognizes if the email being entered does not exist in the database.
I have been stuck on this for far too long and really need some help. I am new with code-igniter and am really confused as to why this is happening. Any help is greatly appreciated.
Here is my code:
Form:
<?php
echo form_open('auth/validate_credentials_login');
echo "<span class='errors_login'>";
echo form_error('email_login');
echo "</span>";
echo form_label('', 'Email', 'email_login');
$data = array( 'name' => 'email_login', 'class' => 'input', 'placeholder' => 'Email');
echo form_input($data, set_value('email_login'));
echo "<span class='errors_login'>";
echo form_error('password_login');
echo "</span>";
echo form_label('', 'Password;', 'password_login');
$data = array( 'name' => 'password_login', 'class' => 'input', 'placeholder' => 'Password');
echo form_password($data, set_value('sha1(password_login)'));
echo form_submit('submit_login', 'Login');
echo form_close();
?>
Controller:
function validate_credentials_login()
{
$this->load->library('session');
$this->load->helper(array('form','url'));
$this->load->model('user_model', 'um');
$this->load->library('encrypt');
$this->load->library('form_validation');
$this->form_validation->set_rules('email_login', 'Email', 'required');
$this->form_validation->set_rules('password_login', 'Password', 'required');
$login = $this->input->post('submit_login');
if($login) {
if($this->form_validation->run() == FALSE)
{
$data['main_content'] = 'home/home_page';
$this->load->view('includes/templates/home_page_template', $data);
}
else
{
$user = $this->um->validate_home_login(array('email' => $this->input->post('email_login')));
if($user->password == $this->encrypt->sha1( $user->salt . $this->encrypt->sha1($this->input->post('password_login')))) {
$this->session->set_userdata(array(
'email' => $this->input->post('email_login')
));
redirect('account/edit');
exit;
}
}
}
}
thanks in advance!
That’s because you have no
elsecondition here:Everything else in your list sounds like expected behavior, but you might need to make sure that
$this->um->validate_home_login()is doing what it should.As a side note, no need to
exitafter callingredirect(), it does that for you.Also,
set_value('sha1(password_login)')looks fishy to me, I don’t think it does what you think. It will set the password value to the literal stringsha1(password_login). I don’t suggest you prepopulate the password field at all – just leave it empty.CI’s form validation is definitely not broken, it actually works quite well, so don’t get frustrated. It might be a good idea to review the documentation and experiment with something simpler until you can get everything working properly.
Check out the
is_uniquerule:http://ellislab.com/codeigniter/user_guide/libraries/form_validation.html#rulereference