CodeIgniter Forums
Repopulation form fields with method GET - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Repopulation form fields with method GET (/showthread.php?tid=49814)



Repopulation form fields with method GET - El Forum - 03-04-2012

[eluser]Mr.Data[/eluser]
Hello!
In my HTML code I create a form element with the code
Code:
form_open('url', array('method' => 'get'))
and I want codeigniter to repopulate the fields after submitting the form. However, it isn't working when using the method GET. If I delete the array so that POST is used everything works fine. Why is that so and how do I change that behaviour?


Repopulation form fields with method GET - El Forum - 03-05-2012

[eluser]Mr.Data[/eluser]
Come on, has no one of you ever used a get form in your homepage?


Repopulation form fields with method GET - El Forum - 03-05-2012

[eluser]Matalina[/eluser]
What's the view look like? need more code to help see the problem.


Repopulation form fields with method GET - El Forum - 03-05-2012

[eluser]Aken[/eluser]
If you're using the form helpers like set_value() to repopulate your form, they default to the POST array only. You'd have to create your own functions, or pull from the GET array directly using $this->input->get() (and appropriate security checks).


Repopulation form fields with method GET - El Forum - 03-05-2012

[eluser]Mr.Data[/eluser]
Damn, that's bad. Isn't there a way to fill the post array manually with everything from the get array so that the form helper methods still can be used?


Repopulation form fields with method GET - El Forum - 03-05-2012

[eluser]Mr.Data[/eluser]
OK, I think I will use last parameter of the former helper methods which let you select the default value.


Repopulation form fields with method GET - El Forum - 03-05-2012

[eluser]Aken[/eluser]
There's no point in using set_value() if you're only going to use the default value portion of it. Just check $this->input->value(), sanitize it, then pass it to your view, and echo it out.