[eluser]unsub[/eluser]
hello
I have come up with a solution for checking if a username (or whatever) already exists when adding records. It is written into the controller for the form in question.
I want to first warn newbies (like me) that this might be a bad way to do this, because I'm learning as I go. Copy this at your own risk, it is posted here in an attempt to get advice on how to do it better.
If one of the experts here says it's reasonable code, I will take this warning off.
To experienced code-igniters and extinguishers: I could really use some advice on this.
So, without further preamble, here is my in-controller callback solution:
first, a $rule for the field that needs checking, with a callback:
...then at the bottom, the callback's method.
What this does is checks if the primary key is "" (nothing). If it finds a value being posted, then the current action is an 'edit', so it doesn't bother to check if the name exists - of course it does, the record is being edited.
If the primary key == nothing (""), that means the current action is 'add' and so it checks if the username (in this case) being posted is already in the database:
heh...yeah. I'm not sure about this. Perhaps someone can see why I want help? Any big issues?
Don't get me wrong, it works well. I've run it through the gauntlet and it doesn't fail; but I want to make good things, not just adequate things. It's why I started using CodeIgniter.
I would really appreciate some advice on this; is it OK? any pointers on which way to go to make it better?