Guest User

Untitled

a guest
Aug 11th, 2011
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class My_Form_validation extends CI_Form_validation {
  2.  
  3.     function __construct($rules = array())
  4.     {
  5.         parent::__construct();
  6.         $CI =& get_instance();
  7.         $this->_config_rules = $rules;
  8.     }
  9.  
  10.     // --------------------------------------------------------------------
  11.  
  12.     /**
  13.      * Unique
  14.      *
  15.      * @access  public
  16.      * @param   string
  17.      * @param   field
  18.      * @return  bool
  19.      */
  20.     function unique($str, $field)
  21.     {
  22.         $CI =& get_instance();
  23.         list($table, $column) = explode('.', $field, 2);
  24.  
  25.         $CI->form_validation->set_message('unique', 'The %s that you requested is unavailable.');
  26.  
  27.         $query = $CI->db->query("SELECT COUNT(*) AS dupe FROM $table WHERE $column = '$str'");
  28.         $row = $query->row();
  29.         return ($row->dupe > 0) ? FALSE : TRUE;
  30.     }
  31. }
  32. ?>
RAW Paste Data