Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter Validation: possible to validate GET query strings?

The form validation library seems to only work on POST. I need to use query strings and would like to use CI to validate the passed values. Is there a way to do this?

like image 742
StackOverflowNewbie Avatar asked Jun 04 '12 15:06

StackOverflowNewbie


4 Answers

The current Codeigniter 3.0 development branch provides an option to insert your own variable instead of $_POST. So you could start using 3.0.

Alternatively, the only way in CI2.1 is to do $_POST=$_GET before you run the validation.

like image 172
Laurence Avatar answered Nov 13 '22 22:11

Laurence


See this page for the CodeIgniter 3 solution:- http://www.codeigniter.com/userguide3/libraries/form_validation.html#validating-an-array-other-than-post

For CodeIgniter 2 you can do $_POST = $_GET; before $this->form_validation->run() as mentioned above.

like image 3
louisl Avatar answered Nov 13 '22 21:11

louisl


You could overwrite the Form_validation function run in a MY_Form_Validation and modify it.

like image 1
nebulousGirl Avatar answered Nov 13 '22 23:11

nebulousGirl


Reference How do I validate a form field in Codeigniter when using Get parameters?

Before validation rules, set the validation data with the following code.

 $this->form_validation->set_data($_GET);
like image 1
Abdul Rehman Avatar answered Nov 13 '22 22:11

Abdul Rehman