brug tilbagekaldsvalideringsfunktionen
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback_check_user_email');
function check_user_email($email) {
if($this->input->post('id'))
$id = $this->input->post('id');
else
$id = '';
$result = $this->user_model->check_unique_user_email($id, $email);
if($result == 0)
$response = true;
else {
$this->form_validation->set_message('check_user_email', 'Email must be unique');
$response = false;
}
return $response;
}
i model
function check_unique_user_email($id = '', $email) {
$this->db->where('email', $email);
if($id) {
$this->db->where_not_in('id', $id);
}
return $this->db->get('user')->num_rows();
}
brug det samme for brugernavnet....