• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Broken native function calling

#1
[eluser]Unknown[/eluser]
I created a plugin to validate a ZIP code, and had the CI form_validation library use it as a rule. The function was successfully being called, and the result was correct, but it wasn't triggering a form validation error. I poked around in the code, and found this on line 618 of system/libraries/Form_validation.php:

Code:
if ( ! method_exists($this, $rule))
{
    // If our own wrapper function doesn't exist we see if a native PHP function does.
    // Users can use any native PHP function call that has one param.
    if (function_exists($rule))
    {
        $result = $rule($postdata);
                            
        if ($_in_array == TRUE)
        {
            $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
        }
        else
        {
            $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
        }
    }
                        
    continue;
}

$result = $this->$rule($postdata, $param);

if ($_in_array == TRUE)
{
    $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
}
else
{
    $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
}

The code after this block deals with the validation error, but it's never executed due to the continue. I changed it to this:

Code:
$result = TRUE;

if ( ! method_exists($this, $rule))
{
    // If our own wrapper function doesn't exist we see if a native PHP function does.
    // Users can use any native PHP function call that has one param.
    if (function_exists($rule))
    {
        $result = $rule($postdata);
                            
        if ($_in_array == TRUE)
        {
            $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
        }
        else
        {
            $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
        }
    }
}
else
{
    $result = $this->$rule($postdata, $param);

    if ($_in_array == TRUE)
    {
        $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
    }
    else
    {
        $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
    }
}

and that cleared up the problem completely. I hope this helps someone struggling with the same issue...


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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