same rule for is_unique when editing and adding entries |
[eluser]keithics[/eluser]
Hi guys, I hope this will help you. Problem: When adding a new entry with is_unique will work just fine but what about when you want to update the entry using the same form validation rule? is_unique will not work because it will detect that you are adding a duplicate entry. Which sucks, and you will be forced to create a new rule just for that. Prerequisites: 1. when editing, you must pass the primary key as post data (which we mostly do) Example where user_id is the primary key: Code: <input type="hidden" value="1" name="user_id" /> Benefits: 1. Same form validation rule for editing and adding Code: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[eluser]Tominator[/eluser]
I'm solving that problem by copying rules (showed below) in my form_validation config: Code: // after setting post/create rules
[eluser]keithics[/eluser]
that would probably solve it, if you have a lot of tables with is_unique rules.. you will be forced to copy and pasting each of it.
[eluser]gte451f[/eluser]
I like this approach! I don't have to maintain 2 rules, one for edit and one for insert. The passive check should be pretty good but could lead to problems when the table contains composite keys. Thanks for the code suggestion!
[eluser]rei[/eluser]
Hi, How can we set rules using this? I mean how can we pass the primary key to the rules? Can u please give me a sample usage on how to use this rule.Thanks
[eluser]keithics[/eluser]
the function only overrides that current is_unique method. that means you can use it the same way. is_unique[users.username] the primary key is automatically detected. But as gte451f said, if you have Composite Primary Keys in your table, it wont work. http://stackoverflow.com/questions/21794...ngle-table |
Welcome Guest, Not a member yet? Register Sign In |