Welcome Guest, Not a member yet? Register   Sign In
Form_validation callbacks with parameters bug (?)
#1

[eluser]sckarlin[/eluser]
Lifted from this thread:

http://ellislab.com/forums/viewthread/180085/

Apologies if this kind of cross-posting is inappropriate. I'm not sure where to report a bug -- if this is, indeed, one.

For several years, I have used the feature to give a custom callback a parameter in form validation. The new Form_validation code seems to have broken this.

For example, I have call back functions that expect the contents between the square brackets to appear as the second parameter of a callback. A rule might look like this:
Code:
'callback__if_and[foo==bar]'
In this case, I want function _if_and to be called with the POST data as the first parameter and the string 'foo==bar' as the second parameter.

The problem is in approximately line 492 of Form_validation for CI 2.0.0:
Code:
if ( ! in_array('required', $rules) AND is_null($postdata))
{
    // Before we bail out, does the rule contain a callback?
    if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match))
    {
        $callback = TRUE;
        $rules = (array('1' => $match[1]));  // why clobber $rules???
    }
    else
    {
        return;
    }
}

The fix may be to either fix the preg_match regex, or to simply remove the $rules re-assignment after setting $callback to TRUE.
#2

[eluser]sckarlin[/eluser]
Looks like someone else has noticed this, too:

https://bitbucket.org/ellislab/codeignit...r-does-not




Theme © iAndrew 2016 - Forum software by © MyBB