Welcome Guest, Not a member yet? Register   Sign In
Form validation callback custom function question
#1

[eluser]Hartimer[/eluser]
Hi

So, i'm using form validation for, guess what, form validation.
The thing is, this specific form is part of a custom library, therefore i think it would be suitable to place it under a method inside the lib itself.

Code:
class My_Lib{

  var $CI;

  function form(){
    $this->CI =& get_instance();
    $this->CI->load->library('form_validation');
    $this->CI->load->helper('form');
    
    $this->CI->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback__username_exists');

    (...)
  }

  function _username_exists($str){
    if(USERNAME_EXISTS){
      $this->CI->form_validation->set_message('_username_exists', '%s unavailable.');
      return FALSE;
    }
    return TRUE;
  }
}

Problem is, the function "_username_exists" is not called. As far as i can tell, the form validation library tries to run the function as it was part of the controller, not the library. Substituting things accordingly, if the form + callback method are defined within the controller, no problems occur.

Is there anyway the callback functionality can reference a library method?
#2

[eluser]Colin Williams[/eluser]
Callbacks are supposed to be functions of the controller. That's how it works. Did you think the validation class scans all active libraries looking for callback functions?
#3

[eluser]Hartimer[/eluser]
No, that would have serious performance consequences i think Smile

I thought it would search for the function on the caller class.
I guess it makes sense that it looks for it on the controller, just wondering if there were an alternative... and i guess not.




Theme © iAndrew 2016 - Forum software by © MyBB