Welcome Guest, Not a member yet? Register   Sign In
Login form with one error message for any scenario
#1

[eluser]SeasonedCoder[/eluser]
Howdy all,

I'm absolute newbie to CI. After reading the user guide I'm totally impressed :wow:

Well, I need to do the following simple task: I have a login form with username and password. But I don't want to display different error messages like "Username is required" or "Password must be at least X chars in length" for different scenarios. For me it's too verbose. All I want is to display a message like "Failed to login. Please enter valid username and password" in case the user fails to log in for whatever reason.

How do I do it using the form validation library? Any ideas?

Thanks in advance.
#2

[eluser]GSV Sleeper Service[/eluser]
like this? [url="http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#settingerrors"]http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#settingerrors[/url]
#3

[eluser]zutis[/eluser]
What I would do is have a custom callback for the password field which checks the username and password.

Use this->input->post() to access both the username and password in the custom callback function.

Dont set any rules for username as all the checking will be done in the password callback.
#4

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums.

I'd just do my validation as normal, and check for a form_error() on each of the fields, (rather than displaying them), then you can print whatever message you want in it's place.
#5

[eluser]SeasonedCoder[/eluser]
@zutis

I was thinking about something like what you suggest: just have one callback to check both fields and set error message. So, I assume, this is viable solution.

@TheFuzzyOne

I'll try your approach as well, just to make myself more familiar with CI. Btw, you got awesome avatar LOL.




Theme © iAndrew 2016 - Forum software by © MyBB