Check duplicate data in CodeIgniter try to make a callback function
I have a registration form. Here I'm able to check duplicate email by my
custom is unique call back function (Don't try to use is_unique). But it
doesn't returns anything. Here is my code.
Controller -
public function add_member () {
$this->load->library('form_validation');
$post_email = $this->input->post('email_id');
$this->form_validation->set_rules('email_id', 'Email ID',
'required|trim|xss_clean|valid_email|callback_check_duplicate_email['
. $post_email . ']');
$this->form_validation->set_message('check_duplicate_email', 'This
email is already exist. Please write a new email.');
if ($this->form_validation->run() == FALSE) {
// validation failed then do that
$this->load->view('member/reg_form');
} else {
$data['email_id'] = $post_email;
$insert = $this->Con_member->insert_data_to_db($data);
if ($insert) {
$success = "Wao ! You are successfully added to our community.";
$this->session->set_flashdata('message_success', $success);
$this->load->view('member/success_page');
} else {
$error = "Hey this email is already exists in our community.";
$this->session->set_flashdata('message_error', $error);
$this->load->view('member/reg_form');
}
}
}
public function check_duplicate_email($post_email) {
return $this->Model_member->checkDuplicateEmail($post_email);
}
Model -
public function checkDuplicateEmail($post_email) {
$this->db->where('email_id', $email_id);
$query = $this->db->get('my_registration_table');
$count_row = $query->num_rows();
if ($count_row > 0) {
return TRUE;
} else {
return FALSE;
}
}
When I try to submit form with email which is already exists. This
function doesn't stop me and doesn't show the validation error message.
Would anyone here to see what's the problem? Waiting for your help.
Thanks.
No comments:
Post a Comment