CodeIgniter Validation: possible to validate GET query strings?

送分小仙女□ 提交于 2019-11-28 01:37:05

问题


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?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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);


来源:https://stackoverflow.com/questions/10883949/codeigniter-validation-possible-to-validate-get-query-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!