Welcome Guest, Not a member yet? Register   Sign In
Custom validation is not being called on production server but works on localhost
#11

[eluser]Joshua Logsdon[/eluser]
If this is at an impasse then I would start breaking it down to basics.

If you have what Greg last said on your local app (which goes along with http://ellislab.com/codeigniter/user-gui...aries.html) and it is working, I would go as far as overwriting (or removing first) the live site. Maybe it's something silly where a file isn't getting updated or it accidentally got moved to the wrong location (system/libraries vs application/libraries).

If it's double-checked it is the same set of files then it sounds more like a server issue. If making sure files are current and set up properly didn't work, what are the specs for your local XAMPP (I'm guessing Windows) and the live server (I'm guessing LAMP)?
#12

[eluser]vanquish[/eluser]
Aha, much closer now! I found the core root of the problem. The issue lies in lines #754-757 of Loader.php, found in system/libraries/

The main problem is the file_exists on line 757 returns FALSE on the remote host and TRUE on my local host. So this PHP function is causing all the trouble! Is there any way to find out WHY it is not working remotely? My entire CodeIgniter setup is identical on both hosts, and I am working on the latest version of CodeIgniter.

Code:
$subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT;

// Is this a class extension request?            
if (file_exists($subclass)) {
    $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT;

$subclass holds the following path for my custom form validation:
application/libraries/MY_Form_validation.php


Also, I should note that realpath($subclass) returns the full path locally, but just an empty value on the remote server.
#13

[eluser]Joshua Logsdon[/eluser]
Wow, great find! I recently had issues when Codeigniter created files (as apache user) in files I uploaded to the server (as a different server user). So I wonder if there is some of weird file permissions issue going on.

I believe realpath() will be empty (or rather FALSE) if the path is invalid. If you are on a virtual host, maybe there is some issue with paths or aliasing... for some reason the path may not be resolving correctly.

Sorry it's not a clear issue... makes me long for a missing semi-colon instead of anonymous server issues.
#14

[eluser]vanquish[/eluser]
It took some digging to find that! I checked the permissions and user of the files through my File Manager in Plesk, and they are all 644 rwx r-x r-x, with the user set the same name as the FTP user of the site.
#15

[eluser]Joshua Logsdon[/eluser]
I bet Smile I just checked and mine are also 644. Ok, I guess scratch out permissions error.

It's got to be that file_exists isn't finding the file... that may make sense why realpath() is returning FALSE on a "non-existent" file.

I have to use that term loosely because if you can see it there, it's PHP that can't resolve it's existence for some reason... and if it can't be a permissions issue... then it must be a path issue... but if everything else (maybe try extending another CI Library class and testing?) is working... well dang.

If it doesn't turn out to be a path issue (for testing, maybe try fiddling with realpath() and that file's absolute location just to make sure you can get to your file through PHP at those extremes), I'm at a loss!
#16

[eluser]vanquish[/eluser]
GOT IT WORKING!

I echoed out the full $subclass path and CodeIgniter was capitalizing the first 'f' in MY_form_validation. So CodeIgniter was casting the filename to MY_Form_Validation and thus making itself think the file didn't exist! It was doing this even though I never used uppercase in my class extension.

So I had been doing my_form_validation or MY_form_validation the whole time when it should have been MY_Form_validation

Joshua, Greg and everyone else - thanks so much for your help! Your patience and support were a great comfort through the process of solving this frustrating bug.
#17

[eluser]Joshua Logsdon[/eluser]
Good deal, I'm glad you got it worked out and it wasn't a more serious issue.

This will be a good reference post next to the file naming conventions, etc.
#18

[eluser]CISCK[/eluser]
I've been scratching my head with this problem for some time now. Just changed "MY_Form_Validation.php" to "MY_Form_validation.php" and it worked perfectly. Thanks so much!
#19

[eluser]neal789[/eluser]
I've been having a similar problem to "vanquish". Custom validation rules aren't working on my development server however they are working on my local MAMP server. The big difference between my problem and Vanquish is that the custom validation file (ie. MY_Form_validation.php) is being included. It even works on the development server if I overwrite a stock CI validation rule. For example I can overwrite the required() function in MY_Form_validation.php and it works perfectly. However when I create a new rule it doesn't seem to see it. I don't get an error either. Nothing happens. It just seems to skip that validation item.

So for one particular form field I have the following validation rules
Code:
// A Snippet from my form validation config file.
...
                        array(
                            'field'    =>    'email_addresses',
                            'label'    =>    'Email Addresses',
                            'rules'    =>    'trim|required|valid_emails|max_emails[3]'
                            ),
...

So for the email_addresses field, "required" validates correctly, even if I overwrite the native CI rule with a custom rule. Valid_emails rule also validates correctly. However the "max_emails" rule seems to be ignored as if it weren't there, but only on my development server. On my local MAMP server it works perfectly.

Here is the max_emails function:
Code:
...
function max_emails($str, $val)
    {
        log_message('debug','MAX EMAILS: '.$str.' '.$val);
        if (strpos($str, ',') === FALSE)
        {
            return TRUE;
        }
        
        $i=0;
        foreach(explode(',', $str) as $email)
        {
            if (trim($email) != '' && $this->valid_email(trim($email)) !== FALSE)
            {
                $i++;
                if($i>$val) return FALSE;
            }
        }
        
        return TRUE;
    }
...

Whatever the problem is, it doesn't seem to be specific to this rule since I'm having the same problem with a different custom validation rule on a different development branch.

Any thoughts/help/solution would be greatly appreciated.

Cheers,
Neal




Theme © iAndrew 2016 - Forum software by © MyBB