In my REST application I am trying to send a json object to the my API server and the server have to validate the data to ensure that every thing is going as expected.
The controller that does the validation on the API server
$this->load->model('api/central');
$this->load->library('form_validation');
//validation rules
$this->form_validation->set_error_delimiters('', '');
$this->form_validation->set_rules('id', 'id', 'required|numeric');
$this->form_validation->set_rules('manager', 'manager', 'required|numeric');
$this->form_validation->set_rules('department', 'department', 'required');
$this->form_validation->set_rules('level', 'level', 'required|numeric');
if ($this->form_validation->run() === FALSE) {
$employeeId = $this->form_validation->error('id') ? $this->form_validation->error('id') : $this->post('id');
$manager = $this->form_validation->error('manager') ? $this->form_validation->error('manager') : $this->post('manager');
$department = $this->form_validation->error('department') ? $this->form_validation->error('department') : $this->post('department');
$level = $this->form_validation->error('level') ? $this->form_validation->error('level') : $this->post('level');
$response = array(
'status' => FALSE,
'error' => 'We don\'t have data to display, Minimum information required to process the request is missing',
'authenticated' => TRUE,
'id' => $employeeId,
'manager' => $manager,
'department' => $department,
'level' => $level
);
$this->response($response, 200);
} else {
$response = $this->central->calls_get($this->post('id'), $this->post('manager'), $this->post('department'), $this->post('level'));
$this->response($response, 200);
}
The problem that $this->post('id'), $this->post('manager'), $this->post('department'), $this->post('level')
returns the value that was submitted, but the form_validation library always fail to validate the data although it's sent as expected
Below are some useful http information the http-header ('content-type') = 'application/json' and the data sent via post as an json object like: {"id":"1", "manager": "1", "department":"sales", "level":"1"}