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?
Asked
Active
Viewed 6,633 times
7
-
You can make CodeIgniter think it was from POST, even though it wasn't. `$_POST = $_GET`, maybe? – gen_Eric Jun 04 '12 at 15:39
-
1lol, the whole class is hardcoded to use `$_POST`. So unless you completely override it, then no. – Esailija Jun 04 '12 at 15:46
-
possible duplicate of [How do I validate a form field in Codeigniter when using Get parameters?](http://stackoverflow.com/questions/10524992/how-do-i-validate-a-form-field-in-codeigniter-when-using-get-parameters) – Thomas Decaux Jul 28 '14 at 11:49
-
See my answer at http://stackoverflow.com/questions/10524992/how-do-i-validate-a-form-field-in-codeigniter-when-using-get-parameters – Thomas Decaux Jul 28 '14 at 11:49
4 Answers
10
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.

Laurence
- 58,936
- 21
- 171
- 212
-
Could you please provide the "option to insert your own variable instead of $_POST" ? Because i'm migrating to CI 3.0 and all my form_validation are working well except one. I receive GET values and i would like to validate them ... I don't know how to do, thanks ! – maxime1992 Jan 31 '15 at 18:22
-
1I just found out what was the problem ... !!! In CI 3.0, they add a little check. Go to system/librairies/Form_validation.php. Search the "set_rules" function and delete the line : if ($this->CI->input->method() !== 'post' && empty($this->validation_data)) { return $this; } – maxime1992 Jan 31 '15 at 18:30
-
Ive tried $_POST = $GET but the validation->run() still returns FALSE – Zorgarath Apr 30 '15 at 23:00
-
-
@Maxime I agree with you but I dont want to edit the codeigniter core code, did you find another way to do it ? – Nicolas Thery May 02 '16 at 16:31
-
1@NicolasThery sorry it was a long time ago I don't exactly remember. I think I just stick with that even if it was not the best solution obviously ! – maxime1992 May 02 '16 at 19:13
3
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.

louisl
- 99
- 1
- 10
1
You could overwrite the Form_validation function run in a MY_Form_Validation and modify it.

nebulousGirl
- 1,364
- 2
- 13
- 23
1
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);

Community
- 1
- 1

Abdul Rehman
- 1,662
- 3
- 22
- 36