Validation and GET values

#1
[eluser]Zarate[/eluser]
Hi there,

I'm looking at the validation class and it seems it only works with POST data, is this true? I've looking through the docs, the forum and the actual code and i haven't found a way of using the validation class with GET params.

Am i missing something?

What i want to do is validate the data coming in the URL. For example:

wadus.com/products/123

I want to check out 123 is a number, no longer than 8 characters, no SQL injection, bla, bla, bla. Can't i do that?

Right now i'm just thinking about copying the GET array to the POST array and run the validation class... but i'd want to do it "right".

Thanks!

#2
[eluser]xwero[/eluser]
I've made a validation library that makes it possible to validate globals and even normal values. It's in an alpha stage but i'm working on it to move into beta stage as fast as possible, now i have one feature to add and a whole bunch of rules. Validate.

The library is different from the CI validation library for your case that it doesn't alter the input that should be done by the input class.

The usage for your case is
Code:
$validate[0]['input'] = $this->uri->segment(2);
$validate[0]['input_type'] = 'value';
$validate[0]['rules'] = 'number|maximum:8'; // number is not yet a rule

Rules are easy to make. They all have a boolean output and it is a function per file.

#3
[eluser]Zarate[/eluser]
Nice!

I'm going to download and test, whatever i find i'll post it here.

Thanks!

#4
[eluser]xwero[/eluser]
The method you can extend the input class with to alter the input is
Code:
function alter_input($value,$functions)
{
    $func_arr = explode('|',$functions);
    foreach($func_arr as $func)
    {
       if($func == 'xss')
       {
         $value = $this->xss_clean($value);
       }
       else
       {
          if(function_exists($func))
          {
             $value = $func($value);
          }
       }
    }
}

It's a quick fix method. I will post an extended input class soon.

#5
[eluser]Zarate[/eluser]
Got the download, and trying to make it work. This what i have:

$validate = array();
$validate[] = array('input'=>$rewrite,'input_type'=>'value','rules'=>'maximum:250');

And i get this error:


--------------------------
Message: Undefined variable: func_array
Filename: libraries/validate.php
Line Number: 206

Message: array_merge() [function.array-merge]: Argument #1 is not an array
Filename: libraries/validate.php
Line Number: 206
--------------------------

It seems you're not initializating $func_array anywhere. If i do it, i can run the app without errors, but is not passing validation, when it should. Trying to debug, the rule name is not being created properly, therefore the helper cannot be loaded and thus the validation fails.

Any ideas?

Thanks!

ps: validate class doesn't seem to have a "do" method and it appears in the docs. I'm using run for the time being.

#6
[eluser]xwero[/eluser]
I've uploaded the fixed class and i also found a bug in the required rule. The file

Thanks for making me aware of the do method in the documentation.

#7
[eluser]Zarate[/eluser]
Close, but not quite there yet.

First, i think you accidentally forgot a couple of "var_dump" calls in validate class.

Then, I was trying to use the "maximum" rule, but i was getting this error:

"No validate function matches maximum"

And that's because i got confused between "application helpers" and "system helpers", but i finally got it right.

Just to point out there's a double "//" in the path (line 26).

Apart from that, it seems to work!

Thanks : )

Juan


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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