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

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?

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.

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

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

Edit: To late!

Thanks anyway Smile

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

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

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

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

For large amounts of fields use something like this:-

$data['fields'] = $_POST

Then you have all the post data in that variable.

[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

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

Theme © iAndrew 2016 - Forum software by © MyBB