CodeIgniter Forums
$this->form_validation->error_array() not work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: $this->form_validation->error_array() not work (/showthread.php?tid=506)



$this->form_validation->error_array() not work - artha.nugraha - 12-11-2014

please help, i'll try this code in my localhost is working but not in may hosting server.

PHP Code:
public function register() {
         
$this->load->library('form_validation');
           
$this->output->set_content_type('application_json');
           
$this->form_validation-set_rules('name','UserName','required|min_length[4]|max_length[16]|is_unique[user.username]');
           if (
$this->form_validation->run() == false){
               
$this->output->set_output(json_encode([$this->form_validation->error_array()]));
               return 
false;
           }
  } 



RE: $this->form_validation->error_array() not work - Rufnex - 12-11-2014

What is the error on you hosting server. I think it could be a path problem or settings.


RE: $this->form_validation->error_array() not work - trentramseyer - 12-11-2014

(12-11-2014, 03:01 AM)artha.nugraha Wrote: please help, i'll try this code in my localhost is working but not in may hosting server.


PHP Code:
public function register() {
 
        $this->load->library('form_validation');
 
          $this->output->set_content_type('application_json');
 
          $this->form_validation-set_rules('name','UserName','required|min_length[4]|max_length[16]|is_unique[user.username]');
 
          if ($this->form_validation->run() == false){
 
              $this->output->set_output(json_encode([$this->form_validation->error_array()]));
 
              return false;
 
          }
 
 


Please turn on your error output and post that with this
try ini_set('display_errors', 1); in your index.php file.

Without seeing the error, could be
is_unique[user.username] is not working do to not being able to connect to database properly.
or
$this->output->set_output(json_encode([$this->form_validation->error_array()])); is not parsing correctly.