1 2 3 4 5 6 7 8 9 10 11 12 |
$id = 2; $this->load->library('form_validation'); if ($this->input->server('REQUEST_METHOD') == 'POST') { $this->form_validation->set_rules('user_email', 'Email', 'min_length[5]|valid_email|required|xss_clean|callback_is_unique_email['.$id.']',array('required'=> 'You have not provided %s.','is_unique'=> 'This %s already exists.')); $this->form_validation->set_message('is_unique_email', 'Email Address already in use'); $this->form_validation->set_message('valid_email', 'Please enter valid email address'); if ($this->form_validation->run() == FALSE) { echo 'error'; } else { echo 'success'; } } |
1 2 3 4 5 6 7 8 9 10 |
function is_unique_email($email, $id) { $this->db->where('user_email', $email); $this->db->where('id !=', $id); $query = $this->db->get('users'); if($query->num_rows() > 0) { return false; } else { return true; } } |