• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom validation rules not working. But only on Development server.

#1
[eluser]neal789[/eluser]
I’ve been having a problem where custom validation rules aren’t working on my development server however they are working on my local MAMP server. The custom validation file (ie. MY_Form_validation.php) is seen by the application. It even works on the development server if I overwrite a native 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 in MY_Form_validation.php. "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

#2
[eluser]neal789[/eluser]
Anybody heard of anything like this before?

#3
[eluser]WanWizard[/eluser]
No.

Time for some serious debugging of the form_validation library. Line 615 checks if a method is defined for the rule. Add some debugging there.
If no method exist with the requested name in the form validation class, and no function of that name exists, it skips the rule quietly.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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