Form Valadation |
[eluser]R_Nelson[/eluser]
I have a simple Registration script that takes in first_name, last_name, email, username, & Password/password_confirm. The problem i have right now is say i use "test" as username and [email protected] for email they both pass the validation but i get an error from the DB because they are suppose to be unique because there already in the DB. I can fix this with simple DB query's but how do i pass the errors along so they show up when i use Code: echo validation_errors();
[eluser]bubbafoley[/eluser]
you can create a custom rule with a callback function http://ellislab.com/codeigniter/user-gui...#callbacks
[eluser]R_Nelson[/eluser]
just want to make sure i am reading this right all i need to do is add Code: callback_username_check Code: $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]'); if its really that easy i really need to start reading more lol thx
[eluser]R_Nelson[/eluser]
i found an even better way to do this by extending the form_validation class Code: class MY_Form_validation extends CI_Form_validation { so i just change my validation string to Code: $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|unique[user.username]'); thank you very much for the help i doubt i would have found this without knowing about the callback!
[eluser]JonoB[/eluser]
You may want to check if the user is updating or inserting a record. If updating some fields in a record (and the username field is not being updated), then a dupe will be incorrectly found.
[eluser]R_Nelson[/eluser]
Don't really expect the site to be that popular but just in case how do i do that?
[eluser]JonoB[/eluser]
[quote author="R_Nelson" date="1300476266"]Don't really expect the site to be that popular but just in case how do i do that?[/quote] I assume that you will either have a hidden form field, or store the user.id in the session. So, when you run your database validation to check for dupes, do something like: Code: //$id is the primary key for the table. If it is greater than zero, then it means that the record already exists |
Welcome Guest, Not a member yet? Register Sign In |