• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form_validation callbacks with parameters bug (?)

Lifted from this thread:


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:
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:
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???

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

Looks like someone else has noticed this, too:


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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