codeigniter validation unique code example
Example 1: codeigniter form_validation email
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
Example 2: form validation input inside api codeigniter
$this->form_validation->set_rules('user_api_key', 'User Api Id', 'trim|required');
if ($this->form_validation->run() == FALSE) {
$data = strip_tags($this->form_validation->error_string());
return $this->json_out($data, 0, $code = 'form_validation_error', $msg = 'Some Fields are required');
}
Example 3: is_unique in codeigniter form validation
$this->form_validation->set_rules('order_no', 'Order no', 'required|callback_check_order_no');
Example 4: is_unique in codeigniter form validation
function check_order_no($order_no) {
if($this->input->post('id'))
$id = $this->input->post('id');
else
$id = '';
$result = $this->Data_model->check_unique_order_no($id, $order_no);
if($result == 0)
$response = true;
else {
$this->form_validation->set_message('check_order_no', 'Order no already exist');
$response = false;
}
return $response;
}