New is_unique form validation method NOT WORKING! [SOLVED] - 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: New is_unique form validation method NOT WORKING! [SOLVED] (/showthread.php?tid=47620) |
New is_unique form validation method NOT WORKING! [SOLVED] - El Forum - 12-15-2011 [eluser]Steve Goodwin[/eluser] So i've been playing around with this most of the afternoon, i've read the documentation and tried multiple ways of calling this in the code, but still no joy. I want to check weather the users email is unique, the table is called "member_tbl" and the field is called "email". My controller code is as below: Code: public function register() My View code is below: Code: <p><?php echo $content; ?></p> Is there anything I'm doing wrong or is CI 2.1.0 to blame? New is_unique form validation method NOT WORKING! [SOLVED] - El Forum - 03-07-2012 [eluser]spiderking[/eluser] Hello ! This was a great help. But i just wanna add something, if you are checking to see if a email/ or a similar user name has already been registered, then you might also add a line like this : Code: $lang['is_unique'] = "This email/username has aleady been registered."; in their "form_validation_lang.php" located under system/language/english/. This will add/ display the appropriate error message when a user attempt to register twice. Thanks New is_unique form validation method NOT WORKING! [SOLVED] - El Forum - 03-17-2012 [eluser]jmc_1014[/eluser] you should extends your library and not editing system folder create a file MY_Form_validation.php in application\libraries <?php class MY_Form_validation extends CI_Form_validation{ function is_unique($str, $field) { list($table, $field) = explode('.', $field); $this->CI->form_validation->set_message('is_unique','The %s is not available'); if (isset($this->CI->db)) { $query = $this->CI->db->where($field, $str)->get($table); return $query->num_rows() === 0; } return FALSE; } } try it it works for me New is_unique form validation method NOT WORKING! [SOLVED] - El Forum - 03-17-2012 [eluser]jmc_1014[/eluser] Quote:[quote author="jmc_1014" date="1332010710"]you should extends your library and not editing system folder[/quote] Quote: Quote: |