CodeIgniter Validation: possible to validate GET q

2019-01-25 19:32发布

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?

4条回答
成全新的幸福
2楼-- · 2019-01-25 20:11

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);
查看更多
\"骚年 ilove
3楼-- · 2019-01-25 20:21

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.

查看更多
Melony?
4楼-- · 2019-01-25 20:23

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

查看更多
戒情不戒烟
5楼-- · 2019-01-25 20:26

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.

查看更多
登录 后发表回答