CodeIgniter Forums
CodeIgniter 3 - Callable Form Validation via Config file not working? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: CodeIgniter 3 - Callable Form Validation via Config file not working? (/showthread.php?tid=61936)



CodeIgniter 3 - Callable Form Validation via Config file not working? - VeeDee - 06-01-2015

I am unable to get the callable form validation feature of CodeIgniter 3 to work when the validation rules are placed in a separate config file.

I am getting the following error message:

Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Config::$form_validation_callback_library

The config file with the form validation rules are as follows (config/fvalidation.php):

Code:
$config['client_details'] = array(
   array(
           'field' => 'client_abn',
           'label' => 'Client ABN',
           'rules' => array('trim', 'required', array('abn_callable', array($this->form_validation_callback_library, 'abn_check'))),
           'errors' => array('abn_callable' => 'Invalid ABN has been entered %s.')
   )
);

The form validation class attempting to be called is (i.e. $this->form_validation_callback_library):

Code:
class Form_validation_callback_library
{

   public function abn_check()
   {

       $this->load->library('abn_validator');

       $abn = $this->input->post_get('abn', TRUE);

       if (!$this->abn_validator->isValidAbn($abn)) {
           return FALSE;
       }

       return TRUE;

   }


}

The controller is:

Code:
$this->load->library('form_validation_callback_library');
        $this->config->load('fvalidation');
       $validation_rules = $this->config->item('client_details');
       $this->form_validation->set_rules($validation_rules);              

       if ($this->form_validation->run() == FALSE) {
           // show form
       } else {
           // process form data
       }

Any help would be greatly appreciated.

Cheers, VeeDee


RE: CodeIgniter 3 - Callable Form Validation via Config file not working? - Avenirer - 06-02-2015

In what location is the Form_validation_callback_library class?


RE: CodeIgniter 3 - Callable Form Validation via Config file not working? - VeeDee - 06-02-2015

(06-02-2015, 01:30 AM)Avenirer Wrote: In what location is the Form_validation_callback_library class?

Its in the libraries folder. i.e. application/libraries/form_validation_callback_library.php

I also load it in the controller before the set_rules() take place.


RE: CodeIgniter 3 - Callable Form Validation via Config file not working? - VeeDee - 06-02-2015

I don't this is currently supported on CodeIgniter 3.

I created a workaround to solve it but hopefully callable validation via config files will be supported in future versions:

http://stackoverflow.com/questions/30585229/codeigniter-3-callable-form-validation-by-config-file-not-working/30609283#30609283