Welcome Guest, Not a member yet? Register   Sign In
Fix for undesired result of the valid_ip form validation rule forcing it to be required field
#1

[eluser]CroNiX[/eluser]
The valid_ip form validation rule runs through the input->valid_ip checker. This in essence makes the field a required field and will fail if empty. Might not be a big deal in some applications, but I have come across an occasion or two where I needed to only check for a valid ip if the field was required by the required rule and ignore it if not required.

Original Rule:
Code:
function valid_ip($ip)
{
    return $this->CI->input->valid_ip($ip);
}

The fix is simple, just override it in your MY_Form_validation class.

Code:
function valid_ip($ip)
{
    if( !empty($ip)) return $this->CI->input->valid_ip($ip);
    return TRUE;
}
Now in your validation rules if you specify "required|valid_ip" it will first check to make sure its not empty and then check to see if its a valid ip.

If in your validation rules you just specify "valid_ip" it will only check the field for a valid ip if its not empty, making it not required like I think it should be. Tongue




Theme © iAndrew 2016 - Forum software by © MyBB