title: Codeigniter return validation error from helper function
body: <p>I have a helper function that checks if a username is valid. </p>
  
  <p>In helper file:</p>
  
  <pre><code>if ( ! function_exists('valid_username'))
  {
      function valid_username($username)
      {
          $ci=&amp; get_instance();
          $ci-&gt;load-&gt;database(); 
  
          if (empty($username) OR !preg_match("/^[a-z]([0-9a-z_-])+[0-9a-z]$/i", $username)) //Allowed a-z, 0-9, and underscores. Must end in a-z or 0-9.
          {
              $ci-&gt;form_validation-&gt;set_message('valid_username', 'Characters not valid.');
              return FALSE;
          }
  
          $ci-&gt;db-&gt;select('username');
          $ci-&gt;db-&gt;where('username', $username);
          $ci-&gt;db-&gt;where('activated', 1);
          $ci-&gt;db-&gt;where('banned', 0);
          $ci-&gt;db-&gt;limit(1);
          $query = $ci-&gt;db-&gt;get('users');
  
          if ($query-&gt;num_rows() &gt; 0) //if user exists
          {
              return TRUE;
          }
          else
          {
              $ci-&gt;form_validation-&gt;set_message('valid_username', 'The %s does not exist.');
              return FALSE;
          }
      }
  }
  </code></pre>
  
  <p>In my controller I am adding the helper to my form validation:</p>
  
  <pre><code>$this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required|xss_clean|min_length[2]|max_length[50]|callback_valid_username');
  
  //add callback from helper function
  function valid_username($username)
  {
      return valid_username($username);
  }   
  </code></pre>
  
  <p>This works well however I have to make the callback private like so:</p>
  
  <pre><code>$this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required|xss_clean|min_length[2]|max_length[50]|callback__valid_username');
  
  function _valid_username($username)
  {
      return valid_username($username);
  }   
  </code></pre>
  
  <p>After making the callback private I get the following message upon submitting an invalid username:</p>
  
  <blockquote>
    <p>Unable to access an error message corresponding to your field name.</p>
  </blockquote>
  
  <p>What am I doing wrong here?</p>