Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
- /**
- * MY_Form_validation Class
- *
- * Extends Form_Validation library
- *
- * Adds one validation rule, "unique" and accepts a
- * parameter, the name of the table and column that
- * you are checking, specified in the forum table.column
- *
- * Note that this update should be used with the
- * form_validation library introduced in CI 2.0.2
- */
- class MY_Form_validation extends CI_Form_validation {
- function __construct($config)
- {
- parent::__construct($config);
- }
- // --------------------------------------------------------------------
- /**
- * Unique
- *
- * @access public
- * @param string
- * @param field
- * @return bool
- */
- function unique($str,$field)
- {
- $CI =& get_instance();
- $CI->load->database();
- list($table, $column) = split("\.", $field, 2);
- $CI->form_validation->set_message('unique', 'The %s that you requested is unavailable.');
- $query = $CI->db->query("SELECT $column FROM $table WHERE $column = '$str' limit 1");
- return ($query->num_rows() > 0) ? FALSE : TRUE;
- /**
- * $query = $CI->db->query("SELECT COUNT(*) AS dupe FROM $table WHERE $column = '$str'");
- * $row = $query->row();
- * return ($row->dupe > 0) ? FALSE : TRUE;
- */
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement