Welcome Guest, Not a member yet? Register   Sign In
Form Validation config called by URL not Method?
#1

[eluser]theshiftexchange[/eluser]
Hi guys,

I've got a small issue with Form Validation class.

Basically I've got a lovely form_validation.php file setup with all my form validation in there. It works on all my forms and is nice and clean.

However, I've discovered that the config file seems to be called by what URL is entered, rather than what method is called?

For example, I have a controller called "auth", with a method called "reset_password()"

If I go to:

/localhost/auth/reset_password

the form will be correct validated as per my config file. But if I call:

localhost/auth/reset_password/3213/42132135

and pass some variables to the method, the form validation is not performed because the config file is never called.

Is this a bug? Or am I missing something?
#2

[eluser]theshiftexchange[/eluser]
Quote:When a rule group is named identically to a controller class/function it will be used automatically when the run() function is invoked from that class/function.

That is from the user guide.

I ran some more tests. I have another function "auth/login" which works fine.

If I manually type "auth/login/awfqf" it loads the "login" page fines (and discards the random variable obviously). But then form-validation is broken on that page too.

Seems to be a bug? Adding an variable after a method call invalidates the config calling function?

I'll bug report this if someone else agrees with me - I just dont want to report a bug if it turns out I'm missing something
#3

[eluser]Dam1an[/eluser]
You can always pass the name of that validation group into the if run check

I think it might not call the validation, as it can't find that exact URI, and it might be routed (although I'd imagine it would call the rerouted segments)
#4

[eluser]theshiftexchange[/eluser]
[quote author="Dam1an" date="1242417797"]You can always pass the name of that validation group into the if run check

I think it might not call the validation, as it can't find that exact URI, and it might be routed (although I'd imagine it would call the rerouted segments)[/quote]

Yeah - that's what I'm doing as a fix.

I guess my question is do you think this is a bug? Shouldnt the form_validation config get called due to a method getting called, not a url been entered?
#5

[eluser]Dam1an[/eluser]
I just reread that part of the userguide, and it says
Quote:When a rule group is named identically to a controller class/function it will be used automatically when the run() function is invoked from that class/function.
So its refering to just the first 2 segments, and not any paramters

If you want to be extra sure, you could check how its implemented, then you'll know if its intentional Wink
#6

[eluser]theshiftexchange[/eluser]
Well - it just doesnt make sense; why have the 'validation' fail if you pass a param to the method? Makes no sense - especially when the user guide states its due to a class/method call and not a url/variable pass.

Its late here, so I'll log a bug report in the morning...
#7

[eluser]Dam1an[/eluser]
Maybe its because you would do something differantly based on the parameter? Although in that case, I'd still assume it would default to the correct validation set, which you can override if needed
#8

[eluser]theshiftexchange[/eluser]
Ahhh... found the code in the system library:

Code:
// Is there a validation rule for the particular URI being accessed?
            $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group;
            
            if ($uri != '' AND isset($this->_config_rules[$uri]))
            {
                $this->set_rules($this->_config_rules[$uri]);
            }
            else
            {
                $this->set_rules($this->_config_rules);
            }

And I did some var_dumps of the system library aswell.

It simply grabs the whole URI, and tests it from that, rather than testing for the controller/function that called it.

It wouldnt be a problem if it just took the /[first]/[second]/ and discarded the rest - but it takes the whole URI [/first]/[second]/[/third]/ and then fails as a result...
#9

[eluser]theshiftexchange[/eluser]
[quote author="Dam1an" date="1242420888"]Maybe its because you would do something differantly based on the parameter? Although in that case, I'd still assume it would default to the correct validation set, which you can override if needed[/quote]

True - but thats not documented anywhere.

so its either

a) undocumented feature
or
b) bug
#10

[eluser]Dam1an[/eluser]
You could change the line where it gets the URI to get the controller and method from the router class
That will return the controller/method being executed, even if its not the same as the URI

Or if you do file it as a bug report, mention that as the suggested fix




Theme © iAndrew 2016 - Forum software by © MyBB