rest - codeigniter form validation always false with json data -


i using codeigniter build own rest web service, application have resource called "calls" , can access via post method,

the "calls" function receive 4 parameters [id, manager, department, level] json object via curl call using content-type:application/json

then using codeigniter form_validation() library validate request return array of response if no error on form_validation()

the problem form_validation() returns false although can output received value expected.

below code of calls function

function calls_post() {  $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 display, minimum information required process request 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); } } 

any advice? :)

http://ellislab.com/forums/viewthread/238080

$_post = json_decode(file_get_contents("php://input"), true); $this->form_validation->set_rules('id', 'id', 'required|numeric'); $this->form_validation->set_rules('department', 'department', 'required');  if($this->form_validation->run() == true) {        $id = $this->input->post('id');      $department = html_escape($this->input->post('department'));         echo $id."<br>".$department;        } else {        echo "false";         } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -