Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 3 - Callable Form Validation via Config file not working?
#1

(This post was last modified: 06-02-2015, 03:58 PM by VeeDee.)

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
Reply
#2

In what location is the Form_validation_callback_library class?
Reply
#3

(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.
Reply
#4

(This post was last modified: 06-02-2015, 06:30 PM by VeeDee.)

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/30585...3#30609283
Reply




Theme © iAndrew 2016 - Forum software by © MyBB