Welcome Guest, Not a member yet? Register   Sign In
Bugs or strange behaviour in the Form_validation library.
#1

[eluser]Bramme[/eluser]
Thread that started it for me: http://ellislab.com/forums/viewthread/130649/

There are two things that bother me with the form validation library. And both are in these lines of the _execute function.
Code:
// If the field is blank, but NOT required, no further tests are necessary
$callback = FALSE;
if ( ! in_array('required', $rules) AND is_null($postdata))
{
    // Before we bail out, does the rule contain a callback?
    if (preg_match("/(callback_.+)/", implode(' ', $rules), $match))
    {
        $callback = TRUE;
        $rules = (array('1' => $match[1]));
    }
    else
    {
        return;
    }
}

First, as explained in the above thread, a \w in the regex that checks for callbacks instead of a . cuts off the optional parameter for custom callbacks. Seems like custom callbacks should support this to me, so that's why I've changed it.

The second problem I have is with the "If the field is blank, but NOT required, no further tests are necessary" logic. This logic is correct in all cases, but one (I think): when you're testing a file input.
The current "required" rule does not check if a file is selected for file inputs. That's why I added a custom callback. However, to clean up my controller, I wanted to move this callback to MY_Form_validation. But since "required" isn't set for the file inputs, the second rule gets skipped over.

I hope I'm making somewhat sense. I'm going to have a look at the "required" part of the _execute function and see if I can improve it a little bit.




Theme © iAndrew 2016 - Forum software by © MyBB