codeigniter form validation rule code example
Example 1: codeigniter load form_validation
<?php
class Form extends CI_Controller {
public function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
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');
}