Welcome Guest, Not a member yet? Register   Sign In
Is there a faster way to get multiple POST data than $this->input->post('data')?
#1

[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?
#2

[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.
#3

[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!
#4

[eluser]stuart_g[/eluser]
Thanks anyway Smile
#5

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

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

[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.
#8

[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.
#9

[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.
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB