is_unique extended - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: is_unique extended (/showthread.php?tid=42924) |
is_unique extended - El Forum - 06-23-2011 [eluser]osci[/eluser] I had a look at is_unique in Form_validaton and while I liked it it lacked the support for validating on edit/update. So I copied it and extended it. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); If you want to validate on create you do as before. Code: $this->form_validation->set_rules('username', 'User', 'is_unique[t_users.username]'); for update you need to pass your unique field name and current value for example for table t_users, username for search, id unique key, $id current unique key value. Code: $this->form_validation->set_rules('username', 'User', 'is_unique[t_users.username.id.'.$id.']'); Hope it helps. is_unique extended - El Forum - 03-08-2012 [eluser]urbankid[/eluser] Great contribution! This should really be included to the main library. and remember: Code: $this->form_validation->set_message('is_unique', 'Custom error message.'); is_unique extended - El Forum - 03-08-2012 [eluser]keithics[/eluser] I posted a similar code here: http://ellislab.com/forums/viewthread/211641/ only that Adding and updating will have the same validation rules. is_unique extended - El Forum - 03-10-2012 [eluser]Noobigniter[/eluser] Thank you so much is_unique extended - El Forum - 03-13-2012 [eluser]sv3tli0[/eluser] Code: public function exists($str, $field) And I add this new method to check if something exists, excelent for username, email checks or others.. Its the same method as is_unique, just it gives the opposite result. |