CodeIgniter Forums
Custom validation is not being called on production server but works on localhost - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Custom validation is not being called on production server but works on localhost (/showthread.php?tid=26912)

Pages: 1 2


Custom validation is not being called on production server but works on localhost - El Forum - 01-26-2010

[eluser]vanquish[/eluser]
Hello,

I have created an extension to the validation form in Codeigniter and it works fine.
I can call all the custom rules and everything works as expected.

Now I uploaded the site to my remote server and my extended form validation is not being called.

Here is what I have :

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class My_form_validation extends CI_Form_validation {
    
    function My_form_validation()
    {
        echo 'called My_form_validation';
        parent::CI_Form_validation();
    }
    
    function check_me()
    {    
      echo 'im running';
    }
}
// End of costum rules

the above works as expected and the constructor is called and echoes the message fine. I even tried putting an echo command before the class and that is working as well on localhost, however NOTHING is being echoed on the production server (the remote server).

This means the custom validation rules class is not being called for some reason ! and only being called when it's running from localhost ?!

The site is running on Apache servers both locally and remotely

Any ideas?

Thanks


Custom validation is not being called on production server but works on localhost - El Forum - 01-26-2010

[eluser]Greg Aker[/eluser]
Is your subclass prefix in your config file 'My_' or 'MY_'? Are you doing development on a case insensitive file system?


Custom validation is not being called on production server but works on localhost - El Forum - 01-26-2010

[eluser]vanquish[/eluser]
Thanks for the reply Greg! My server is case sensitive, so I have made all files lowercase. I don't know if this does anything to CodeIgniter but my experience tells me it's safest to stick with lowercase when dealing with web software.

What do you think the problem is, if it's not the filename?

I did
Code:
$this->load->library('my_form_validation');
and added
Code:
echo 'sdgfsdfg';
in the constructor method, it actually displays "sdgfsdfg" on the screen. Still none of the validation rules work unfortunately - only working locally.


Custom validation is not being called on production server but works on localhost - El Forum - 01-26-2010

[eluser]tomcode[/eluser]
If You haven't changed CI's configuration settings for the subclass_prefix, try this :

1. name the custom validation file MY_Form_validation.php

2. the code :
Code:
class My_Form_validation extends CI_Form_validation {
    
    function My_Form_validation()
    {
        echo 'called My_Form_validation';
        parent::CI_Form_validation();
    }
    
    function check_me()
    {    
      echo 'im running';
    }
}

3. Take out
Code:
$this->load->library('my_form_validation');



Custom validation is not being called on production server but works on localhost - El Forum - 01-27-2010

[eluser]vanquish[/eluser]
Nope, when I change the casing from my_ to MY_ it's still ignored and the echo never shows. It's like the file is invisible to CodeIgniter - no error messages or anything. When I add the line to explicitly load it: $this->load->library('my_form_validation'); I get a "404 File not found" error.


Custom validation is not being called on production server but works on localhost - El Forum - 01-27-2010

[eluser]Greg Aker[/eluser]
vanquish:

check a couple of things.

a.) in your config file, if your subclass prefix is 'MY_' your library class needs to be: MY_Form_validation. (notice the same case on 'my')

b.) To load your lib, you simply need to call $this->load->library('form_validation'); CodeIgniter will handle seeing that you have overridden or added something to the class.

Read the bottom of this page: http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html

-greg


Custom validation is not being called on production server but works on localhost - El Forum - 01-27-2010

[eluser]tomcode[/eluser]
Oups, I had a typo, like Greg has specified, the class specification needs to be MY_Form_validation


Custom validation is not being called on production server but works on localhost - El Forum - 01-27-2010

[eluser]vanquish[/eluser]
Hi Greg, it doesn't work whether I make the prefix caps or lowercase. It works fine locally on XAMPP but nothing on the live server.

Here is my code for the file my_form_validation.php
Code:
class my_form_validation extends CI_Form_validation {
    
    function my_form_validation()
    {
        echo 'called my_form_validation';    
        parent::CI_Form_validation();
    }
}



Custom validation is not being called on production server but works on localhost - El Forum - 01-27-2010

[eluser]Greg Aker[/eluser]
Vanquished, I think we are having a failure to communicate here.

Your subclass prefix found in your config file is 'MY_' right?

If so, your file need to be:

MY_Form_validation.php

your class needs to be:

Code:
class MY_Form_validation extends CI_Form_validation {

   function MY_Form_validation()
   {    
       parent::CI_Form_validation();

       die('yay, this is my form validation class');
   }

}

Look at the loader where it is loading up classes, and the reasoning for this will be clear.

-greg


Custom validation is not being called on production server but works on localhost - El Forum - 01-27-2010

[eluser]vanquish[/eluser]
Hi Greg, as I mentioned I tried with both lowercase and uppercase in both the config line and in the library class/function prefix and it made no difference.