I am using Phil Sturgeon, CI3 and POSTMAN server REST server for debugging. I am sending a PUT with the information below, however I am not receiving the expected error messages.
Here is my form_validation.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); $config = array( 'student_put' => array( array('field' => 'email_address', 'label' => 'email_address', 'rules' => 'trim|required|valid_email'), array('field' => 'password', 'label' => 'password', 'rules' => 'trim|required|min_length[8]|max_length[16]'), array('field' => 'first_name', 'label' => 'first_name', 'rules' => 'trim|required|max_length[50]'), array('field' => 'last_name', 'label' => 'last_name', 'rules' => 'trim|required|max_length[50]'), array('field' => 'phone_number', 'label' => 'phone_number', 'rules' => 'trim|required|alpha_dash'), ) ); ?>
Here is my method in my Api.php controller:
function student_put(){ $this->form_validation->set_data($this->put()); // these are the rules set in config/form_validation.php if ($this->form_validation->run('student_put') != FALSE) { die('good data'); } else { $this->response( array( 'status'=> 'failure', 'message'=> $this->form_validation->get_errors_as_array(), ), REST_Controller::HTTP_BAD_REQUEST ); } }
This is located in my libraries folder as MY_Form_validation.php:
<?php class MY_Form_validation extends CI_Form_validation { function __construct($rules = array()) { parent::__construct($rules); $this->ci =& get_instance(); } public function get_errors_as_array() { return $this->_error_array; } public function get_config_rules() { return $this->_config_rules; } public function get_field_names($form) { $field_names = array(); $rules = $this->get_config_rules(); $rules = $rules[$form]; foreach ($rules as $index=> $info) { $field_names[] = $info['field']; } return $field_names; } }
When I put the following in POSTMAN:
X-API-KEY 123456 first_name test email_address abc
As a result, I get:
{ "status": "failure", "message": [] }
But I have to get validation errors.
As the debugging steps, I confirmed: - no auth errors - read form_validation.php - if I change:
'message'=> $this->form_validation->get_errors_as_array(),
to
'message'=> 'test',
the postman returns:
{ "status": "failure", "message": "test" }
Any help is greatly appreciated.