title: CodeIgniter call a callback within a custom form_validation class
body: <p>Basically I want to use a callback validation method <strong>inside</strong> an extended class of <code>Form_validation</code>.</p>
  
  <p><strong>OK CASE</strong></p>
  
  <p>I make <code>MY_Form_validation</code> class with the public callback method.</p>
  
  <p>Loaded in my controller as:</p>
  
  <pre><code>public function __construct()
  {
      parent::__construct();
      $this-&gt;load-&gt;helper(array('form', 'url'));
      $this-&gt;load-&gt;library('form_validation'); 
  }
  </code></pre>
  
  <p>used in this controller as:</p>
  
  <pre><code>$this-&gt;form_validation-&gt;validate();
  </code></pre>
  
  <p>I use it like this inside the custom form class:</p>
  
  <pre><code>$this-&gt;CI-&gt;form_validation-&gt;set_rules('field', 'field', 'check_callback');
  </code></pre>
  
  <p>Note that it is not called as <code>callback_&lt;name of method&gt;</code> which is I do not know either why it <em>only</em> works without the <code>callback_</code> prefix <em>when</em> called inside its own class.</p>
  
  <p><strong>NOK CASE</strong></p>
  
  <p>I make <code>MY_Custom_form_validation</code> class with the public callback method.</p>
  
  <p>Loaded in my controller as:</p>
  
  <pre><code>public function __construct()
  {
      parent::__construct();
      $this-&gt;load-&gt;helper(array('form', 'url'));
      $this-&gt;load-&gt;library('form_validation');
      $this-&gt;load-&gt;library('my_custom_form_validation');
  }
  
  $this-&gt;my_custom_form_validation-&gt;validate();
  </code></pre>
  
  <p><strong>Same settings as OK CASE when used in <code>set_rules</code> but this time I get the following error</strong>:</p>
  
  <pre><code>Unable to access an error message corresponding to your field name field.(check_callback)
  </code></pre>
  
  <p>Why is this happening? They only differed in file name and way of loading! Did I miss something here? </p>
  
  <p>Or there should only be ONE extended <code>MY_Form_validation</code> that will contain the entire validation for the entire project? Does CI really prevents this custom class <em>aside from</em> <code>MY_Form_validation</code>?</p>
  
  <hr>
  
  <p><code>MY_Form_validation.php</code></p>
  
  <pre><code>&lt;?php
  class MY_Form_validation extends CI_Form_validation
  {
      protected $CI;
  
      public function __construct($rules = array())
      {
          parent::__construct($rules);
          $this-&gt;CI =&amp; get_instance();
      }
  
      public function validate()
      {
          $this-&gt;CI-&gt;form_validation-&gt;set_rules('value', 'value',
              'trim|required|integer|check_value['.$this-&gt;CI-&gt;input-&gt;post('unit').']');
          $this-&gt;CI-&gt;form_validation-&gt;set_rules('unit', 'unit', 'trim|required');
      }
  
      public function check_value($value, $unit)
      {
          if($value &gt;= 100)
          {
              return TRUE;
          }
          else
          {
              $this-&gt;CI-&gt;form_validation-&gt;set_message('check_value',
                  'The %s must be greater than or equal 100.');
              return FALSE;
          }
      }
  </code></pre>
  
  <p><code>MY_Custom_form_validation.php</code></p>
  
  <pre><code>&lt;?php
  class MY_Custom_form_validation extends CI_Form_validation
  {
      protected $CI;
  
      public function __construct($rules = array())
      {
          parent::__construct($rules);
          $this-&gt;CI =&amp; get_instance();
      }
  
      public function validate()
      {
          $this-&gt;CI-&gt;form_validation-&gt;set_rules('value', 'value',
              'trim|required|integer|check_value['.$this-&gt;CI-&gt;input-&gt;post('unit').']');
          $this-&gt;CI-&gt;form_validation-&gt;set_rules('unit', 'unit', 'trim|required');
      }
  
      public function check_value($value, $unit)
      {
          if($value &gt;= 100)
          {
              return TRUE;
          }
          else
          {
              $this-&gt;CI-&gt;form_validation-&gt;set_message('check_value',
                  'The %s must be greater than or equal 100.');
              return FALSE;
          }
      }
  </code></pre>
  
  <p><code>Form.php</code>, please note of the <strong>OK CASE</strong> and <strong>NOT OK</strong></p>
  
  <pre><code>&lt;?php
  class Form extends CI_Controller
  {
  
      public function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;helper(array('form', 'url'));
          // OK CASE
          $this-&gt;load-&gt;library('form_validation');
          // NOK CASE
          $this-&gt;load-&gt;library('my_custom_form_validation');
          $this-&gt;load-&gt;model('prf_model');
      }
  
      public function submit()
      {
          $data['username'] = 'my_username';
          $data['title'] = 'Submit a PRF';
          $data['last_order_submission'] =
              ($this-&gt;prf_model-&gt;get_last_prf_order_submission()+1);
  
          // OK CASE
          $this-&gt;form_validation-&gt;validate();
          // NOK CASE
          $this-&gt;my_custom_form_validation-&gt;validate();
  
          if(!$this-&gt;form_validation-&gt;run())
          {
              $this-&gt;load-&gt;view('templates/header', $data);
              $this-&gt;load-&gt;view('pages/form', $data);
              $this-&gt;load-&gt;view('templates/footer', $data);
          }
          else
          {
              $this-&gt;_save_to_database($_POST);
              redirect('form/success');
          }
      }
  </code></pre>