![]() |
Validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Validation (/showthread.php?tid=3785) Pages:
1
2
|
Validation - El Forum - 10-22-2007 [eluser]schnoodles[/eluser] Hello i am currently building a usersystem and i am up to the part where you check to see if the username and password is correct. i was wondering if there is a proper way to throw errors for functions to make them look like it was a validation error. So i could do like Code: if ( $validation->run() == true ) { Anyone know what the best way to accomplish what i am trying to do is ? Validation - El Forum - 10-22-2007 [eluser]xwero[/eluser] I do something like Code: $errors = ''; Validation - El Forum - 10-22-2007 [eluser]schnoodles[/eluser] Ahh that is really nice, i was just wondering if i can add an error message from $user->exists into $this->validation->error_string; at all. So it actually looks part of my user system. Validation - El Forum - 10-22-2007 [eluser]xwero[/eluser] You could use the extended validation library talked about on the forum that enables you to write your own validators but checking if the user exists is not a common task so i don't know why you should need to have this error message as a validator. Validation - El Forum - 10-22-2007 [eluser]xwero[/eluser] as an alternative you could make a callback function where you do the user exists check and you set a custom message but that is stretching the validation library a bit Validation - El Forum - 10-22-2007 [eluser]schnoodles[/eluser] Well that is what i want to do, but the problem is that i need to check the db with username AND password, and not just one or the other. Is there a way to give a normal error message but add it into the validators error message system? Validation - El Forum - 10-22-2007 [eluser]xwero[/eluser] I don't know if it is going to work but you could extend the validation library with a user_exists rule Code: MY_Validation extends CI_Validation Code: $rules['username'] = "user_exists[password]"; Again i don't know if it works but if it does it seems to be a better way to extend the rules than using callbacks. The only drawback is the compatibility with future versions of the CI validation class. Validation - El Forum - 10-22-2007 [eluser]schnoodles[/eluser] Yah this is abit annoying, im going to have to delve into the code see if i can just add errors manually to the error_string because thats all i really want to do. Validation - El Forum - 10-23-2007 [eluser]Michael Ekoka[/eluser] Hey Schnoodles, I don't know if I properly understand what you're asking, but this is what I would do: - to create callback methods in your controller to check uniqueness and password validity: Code: function _is_unique($data){ Alternatively, you can look for the language file /language/english/validation_lang.php and add your error messages there. Following the format that you find in the file, just put the name of the callback method and the custom error message. - Now to authenticate and use the validation mechanism you would do this upon submit: Code: $rules['username'] = 'callback__valid_password'; Validation - El Forum - 10-23-2007 [eluser]schnoodles[/eluser] Not exactly, i cant use a standard callback because i want to compare USERNAME and PASSWORD in one hit. I have found a way around it although i am not sure if its the best way. in Password Rules i use login_match[username] and the code i have is Code: <?php Hopefully that will give everyone a better idea of what i am trying to accomplish there. If anyone has a better way of doing this maybe without subclassing the Validation class i would love to hear it. |