• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My_Form_validation class not loading

#1
[eluser]ChrisHJ[/eluser]
Hi,

I'm trying to use a custom validation class with custom validation rules, but for some reason the class never loads.

The set-up is very simple, so I'm just gonna give it all to you here, starting with my function (in controller 'Bruger') when the button is clicked:

Code:
public function glemt_adgangskode()
    {
        $this->load->library('auth');
        
        $send = $this->input->post('create');
        
        if($send)
        {
            print_r($this->auth->forgot_password($this->input->post('user_email')));
        }
        
        $this->load->view('form');
    }

This should bring us to the auth library, in the function forgot_password($user_email):

Code:
public function forgot_password($user_email)
    {
        $this->ci->load->library('form_validation');
        
        $this->ci->form_validation->set_error_delimiters('<li>', '</li>');
        
        $this->ci->form_validation->set_rules('user_email', 'Email', 'required|tester_valid');
        
        if ($this->ci->form_validation->run() == FALSE)
    {
    $this->data['val'] = validation_errors();
                            
    } else {
        
            $this->data['val'] = "<li>Ny adgangskode bestilt.</li>";
    }
        
        return $this->data;
    }

I have no problem with the build-in rules ('required' works), but my custom rule 'tester_valid' does not.

My test is very simple:
Code:
class My_Form_validation extends CI_Form_validation {

    public function __construct() {
        parent::__construct();
        $ci = & get_instance();
        
        log_message('debug', 'My_Form_validation loaded');
    }
    
    public function tester_valid($var) {
/* doesn't matter, the class never loads! /*
}

The function is empty for now. Like I said, the class is never found by CI, as proved by log:

Code:
DEBUG - 2012-01-28 16:42:13 --&gt; Config Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Hooks Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Utf8 Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; UTF-8 Support Enabled
DEBUG - 2012-01-28 16:42:13 --&gt; URI Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Router Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Output Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Security Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Input Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Global POST and COOKIE data sanitized
DEBUG - 2012-01-28 16:42:13 --&gt; Language Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Loader Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Helper loaded: url_helper
DEBUG - 2012-01-28 16:42:13 --&gt; Helper loaded: form_helper
DEBUG - 2012-01-28 16:42:13 --&gt; Controller Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Form Validation Class Initialized
DEBUG - 2012-01-28 16:42:13 --&gt; Language file loaded: language/english/form_validation_lang.php
DEBUG - 2012-01-28 16:42:13 --&gt; File loaded: /application/views/form.php
DEBUG - 2012-01-28 16:42:13 --&gt; Final output sent to browser
DEBUG - 2012-01-28 16:42:13 --&gt; Total execution time: 0.1228

Im using CI 2.1.0, and in the previous version of ci there was no problem..

The really weird part is that other classes with 'MY_' prefix loads just fine, and I can't for the world figure why this particular one doesn't.

Please help me!


#2
[eluser]Jan_1[/eluser]
It is looking for a function in the same controller.
So, you might just put it there..?
Link to User_Guide

#3
[eluser]ChrisHJ[/eluser]
Hi,
in the controller its calling $this->auth->forgot_password which is a function in the library auth or am I missing something ?

#4
[eluser]Jan_1[/eluser]
and "public function tester_valid($var)" is in the same file like "public function forgot_password($user_email)" ?

#5
[eluser]ChrisHJ[/eluser]
No no. The function 'tester_valid($var)' is placed in the class 'My_Form_validation'.

The problem really is that the class 'My_Form_validation' isn't loading.

Thanks for looking into this!

#6
[eluser]Jan_1[/eluser]
I don't really understand, where you have that class (in the lib?), so I can't say something about that.

But, if you do write
Code:
$this->ci->form_validation->set_rules('user_email', 'Email', 'required|tester_valid');
you are telling your server to look for the "tester_valid"-Funktion just some lines deeper.
If you but it there - the function will work.


#7
[eluser]InsiteFX[/eluser]
Because you have My_ and it should be MY_ !!!
Code:
class MY_Form_validation extends CI_Form_validation {

    private $ci;

    public function __construct() {

        $ci = & get_instance();

        parent::__construct();

        log_message('debug', 'MY_Form_validation loaded');
    }
    
    public function tester_valid($var)
    {
        /* doesn't matter, the class never loads! /*
    }
}

This library should be placed in application/libraries/MY_Form_validation.php

#8
[eluser]ChrisHJ[/eluser]
Jesus christ,
some times you just look so much that u dont see the obvious..
Thanks :-)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.