Welcome Guest, Not a member yet? Register   Sign In
Form_validation and custom check
#1

[eluser]Rvnikita[/eluser]
Hi.
I Have the code like this:

Code:
$this->form_validation->set_rules('bannerfile_fake', 'Файл', 'required|callback_banner_file_check[123]');

function banner_file_check($file, $param)
    {
        echo '<pre>';
            print_r($param);
        echo '</pre>';
        die("!!!");        
    }
And $param don't have '123' value.
It's empty.
I looked at the source code and found in form_validation string 496:

Code:
if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match))

And if I changed it to

Code:
if (preg_match("/(callback_.+)/", implode(' ', $rules), $match))

Everythink is all write.
As I understand, we lose the param, because the preg_march don't understand '[' and ']' with '\w+'
Is this a bug or may be it's bug in my head?
Thank's
#2

[eluser]Michael Wales[/eluser]
It is my understanding that custom callbacks were never meant to have paramaters of this nature passed to them.
#3

[eluser]Matthieu Fauveau[/eluser]
I'm pretty sure this was working in a previous version of CI...
#4

[eluser]xwero[/eluser]
I think it is a bug because why is that callback not allowed to have a parameter, while all other callbacks are allowed to have a parameter.
The context of the troubled line :
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]));
            }
            else
            {
                return;
            }
        }

So the bug occurs when an empty input field is posted and there is callback rule that can handle an empty string but has a parameter.

I didn't know this was possible with the new validation library? Should the documentation be updated to make people aware of this functionality? Or am i dropping the ball on this?
#5

[eluser]helmutbjorg[/eluser]
After quite a LOT of debugging I think I have hit on the same problem. The error occurs for me when I have a form_upload field which when submitting to a form created with a multipart encoding type doesn't appear in the $_POST array. It does however appear in the $_FILES array. Unfortunately the form_validation class only looks at post data.

That means that when the lines of code you are talking about above hits the field the 'is_null' returns true and the parameters are stripped from the callback function.

Perhaps nobody else is hitting this line of code (it should rarely come up) but that regular expression is not correct. It strips the parameters.

I know this is a hard one for people to test for themselves but the question really is:

If that line is simply checking for a callback (before it 'bails' out) then shouldn't it preserve the parameters. The current regular expression strips them "/(callback_\w+)/". Is this intentional? Can anybody please confirm why this is like this?
#6

[eluser]helmutbjorg[/eluser]
Perphaps derek could give us some feedback on this issue?




Theme © iAndrew 2016 - Forum software by © MyBB