CodeIgniter Forums
Is there a faster way to get multiple POST data than $this->input->post('data')? - 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: Is there a faster way to get multiple POST data than $this->input->post('data')? (/showthread.php?tid=23957)



Is there a faster way to get multiple POST data than $this->input->post('data')? - El Forum - 10-27-2009

[eluser]stuart_g[/eluser]
I've written a job application form, which has about 50 fields. Previously I've used the standard $this->input->post('fieldname') to retrieve all the submitted data, but as this form is pretty large I wondered if there's a less tedious and quicker method?

I've looked through the input class but can't see anything obvious. A method to retrieve all post data and put it into an array with the field name as the array key is the sort of thing I'd like. Is this possible?


Is there a faster way to get multiple POST data than $this->input->post('data')? - El Forum - 10-27-2009

[eluser]stuart_g[/eluser]
Nevermind, since code igniter didn't seem to offer a method, I just looped through the global $_POST array myself and assigned the values to an array.


Is there a faster way to get multiple POST data than $this->input->post('data')? - El Forum - 10-27-2009

[eluser]rogierb[/eluser]
Why not loop through $_POST and do a $this->input->post(‘fieldname’) on each element, then put that in a new sanitized array

Code:
foreach ($_POST as $key=>$val)
{
  $sanitized[$key] = $this->input->post($key)
}

Edit: To late!


Is there a faster way to get multiple POST data than $this->input->post('data')? - El Forum - 10-27-2009

[eluser]stuart_g[/eluser]
Thanks anyway Smile


Is there a faster way to get multiple POST data than $this->input->post('data')? - El Forum - 10-27-2009

[eluser]The Mask[/eluser]
Check out Datamapper and the associative array extension methods.


Is there a faster way to get multiple POST data than $this->input->post('data')? - El Forum - 10-27-2009

[eluser]Colin Williams[/eluser]
This is why we need improvements to the user guide. So many people are afraid of $_POST.


Is there a faster way to get multiple POST data than $this->input->post('data')? - El Forum - 10-28-2009

[eluser]stuart_g[/eluser]
[quote author="Colin Williams" date="1256683902"]This is why we need improvements to the user guide. So many people are afraid of $_POST.[/quote]

I think that was the problem. I knew Code Igniter disabled $_GET and encouraged you to use URL segments, so somehow I thought that $_POST must have been altered with also.


Is there a faster way to get multiple POST data than $this->input->post('data')? - El Forum - 10-28-2009

[eluser]Colin Williams[/eluser]
Last time this issue came up I broke down the user guide and while it never says not to use $_POST, there is a bit on the Models page that comes very close to saying that. The main advantage of the input->post() method is that it handles a chunk of logic for you, and optionally does XSS cleansing.


Is there a faster way to get multiple POST data than $this->input->post('data')? - El Forum - 10-28-2009

[eluser]daparky[/eluser]
For large amounts of fields use something like this:-

Code:
$data['fields'] = $_POST

Then you have all the post data in that variable.


Is there a faster way to get multiple POST data than $this->input->post('data')? - El Forum - 10-28-2009

[eluser]Colin Williams[/eluser]
Don't forget to sanitize it first. If you don't have global_xss_filtering on, you'll want to do

Code:
$data['fields'] = xss_clean($_POST);