Welcome Guest, Not a member yet? Register   Sign In
Validation for URL data submitted as POST or GET from external URL
#1

[eluser]Brian Loomis[/eluser]
I'm interested in finding a good method to validate parameterized URI being sent to our application as part of a testing process. I've worked with the form validation but not sure if this is what I want. I've also searched the forums and seem to find no information on validating parameters besides the form validation class. There is a form_validation library and a validation library. However the documentation only references the form_validation library, I'm assuming because most validation is form based.

Does anyone have any suggestions on resources for doing standard validation techniques on data that comes from a URI request and not a form?

Thanks in Advance.
#2

[eluser]Brian Loomis[/eluser]
I've also checked the Packt codeigniter book and the Wrox book with no information about using the libraries in this manner.
#3

[eluser]Brian Loomis[/eluser]
So this is what my code looks like, trying to capture incoming requests and archive them and need to validate if they are valid or not.

class Incoming extends Controller {

function index()
{
parse_str($_SERVER['QUERY_STRING'],$_GET);
// checks for incoming requests:
// Post: http://www.xyz.com/incoming/?z=m&c=3&l=1...=344&f=122

$this->load->helper(array('form', 'url'));
$this->load->library('validation');
$rules['c'] = "required";
$rules['l'] = "required";
$rules['y'] = "required";
$rules['s'] = "required";
$rules['f'] = "required";

$this->validation->set_rules($rules);

$data['info']=$this->validation->run();

if ($this->validation->run() == FALSE)
{
$this->load->view('Incoming_fail',$data);
}
else
{
$data['c']=$this->input->get_post('c', TRUE);
$data['l']=$this->input->get_post('l', TRUE);
$data['y']=$this->input->get_post('y', TRUE);
$data['s']=$this->input->get_post('s', TRUE);
$data['f']=$this->input->get_post('f', TRUE);

$this->load->view('Incoming_index',$data);
}
}
}

So this always triggers that it is invalid, even when all my parameters are present.

What changes can I make to validate get requests instead of form posts?
#4

[eluser]Brian Loomis[/eluser]
I still haven't found a good solution:

There is this one:
http://ellislab.com/codeigniter/user-gui...ation.html

and this:
http://ellislab.com/codeigniter/user-gui...ation.html

But nowhere does validating GET requests covered in the documentation or either of the two CI books I have from PACKT or REILLY. I'd like to validate parameters coming in in query strings.

I think this is because CI does not use query strings as a default and you have to manually override it's default behavior to do this.

Also I've looked into http://ellislab.com/codeigniter/user-gui...sting.html but I'm not interested in doing TDD at this point just having some handy shorthand for validating the querystrings we have coming into the application.
#5

[eluser]Brian Loomis[/eluser]
This seems like it will fit the bill.

Thanks for all your help everyone...

http://codeigniter.com/wiki/Validate/
#6

[eluser]Brian Loomis[/eluser]
That library actually doesn't have a helper it needs, the current version is missing it.

Instead I found another solution using jQuery to convert the GET requests the HTTP links were generating to POSTS so that the regular form_validation libraries work.

http://code.google.com/p/postlink/

Use Postlink.
#7

[eluser]Matty J[/eluser]
This would still be a useful thing to be able to do though with the CodeIgniter validation library, for an application that needs to support JSONP requests ie. input validation of get parameters from a querystring.

Cheers
Matt




Theme © iAndrew 2016 - Forum software by © MyBB