Welcome Guest, Not a member yet? Register   Sign In
Best practice for Login/Password form validation errors?
#1

[eluser]Jakobud[/eluser]
I'm a newbie to CI but I love it so far. As I move forward into learning more about CI I want to try to stick with best practice coding techniques.

Right now, I'm making a basic login/password form for a database-driven website. When the user enters a username and password, the controller checks the values against the database and logs in the person if correct. Otherwise I want a login error to be displayed on the login view. This login error is what I'm trying to figure out.

The first thing I thought was to use the Form Validation library, because it automatically generates errors to display using the validation_errors() method in the view. But is this the correct approach? Seems like form validation library is used to determine stuff like "Is the username the minimum length" or "does the password match the password confirmation input" and stuff like that.

I just want to check the submitted values against whats in the database (which I know how to do) and then display an error back on the same login form view if it doesn't match up. Whats the best way to accomplish this?

I was thinking maybe just doing:
Code:
if ( validate_login() == false )
{
   $data['errorMsg'] = "Invalid Username";
   $this->load->view('login_view', $data);
}

And then displaying $errorMsg in the view... That seems kinda hacky though.

Anyone have a direction they could point me in or an example I could take a glance at? Is the form validation library the best approach?


Messages In This Thread
Best practice for Login/Password form validation errors? - by El Forum - 01-19-2010, 12:33 PM



Theme © iAndrew 2016 - Forum software by © MyBB