CodeIgniter Forums
how to get all post data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: how to get all post data (/showthread.php?tid=32808)



how to get all post data - El Forum - 08-05-2010

[eluser]Arun Joshi[/eluser]
I have a dynamically built form. And there is lot of controls. I cant define each controls name initially. In this case when I submit form, how can i get all the post data from that form?

similarly
Code:
var_dump($_POST);
.

I searched in the form. But cant find a solution for this.

Thanks
Arun


how to get all post data - El Forum - 08-05-2010

[eluser]pickupman[/eluser]
You may find this command helpful
Code:
$this->output->enable_profiler(TRUE);

This will output every query, $_REQUEST variable, memory, time, uri. Very helpful for developing. You can using something like
Code:
$this->input->post('field_name');
//or
foreach($this->input->post() as $key => $val)
{
  echo "<p>Key: ".$key. " Value:" . $val . "</p>\n";
}



how to get all post data - El Forum - 08-06-2010

[eluser]Arun Joshi[/eluser]
I tried
Code:
var_dump($this->input->post());

But its not working. I really struck here. any other solution???


how to get all post data - El Forum - 08-06-2010

[eluser]WanWizard[/eluser]
You can't call the post() method that way, you can't iterate over it using a foreach either.

post() requires an index name, if not given (of if it doesn't exist), it returns FALSE, which is probably what your var_dump() output is showing.

What you can do is:
Code:
$post = array();
foreach ( $_POST as $key => $value )
{
    $post[$key] = $this->input->post($key);
}
var_dump($post);

Would be a handy addition to the Input library...


how to get all post data - El Forum - 08-06-2010

[eluser]Arun Joshi[/eluser]
Thanks... I have added that to my library... Smile


how to get all post data - El Forum - 01-29-2012

[eluser]kanjimaster[/eluser]
I use this extension of the Input class. The code is similar to WanWizard's. Just place the code in a file application/core/MY_Input.php.

Code:
&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Input extends CI_Input {

    function dump_post()
    {
        $post = array();
        foreach ( array_keys($_POST) as $key )
        {
            $post[$key] = $this->post($key);
        }
        echo '<pre>'; var_dump($post); echo '</pre>';
    }
}

and call by inserting
Code:
$this->input->dump_post();
into your code.


how to get all post data - El Forum - 01-29-2012

[eluser]InsiteFX[/eluser]
CI 2.1.0
Code:
$data = $this->input->post(NULL, TRUE); // returns all POST items with XSS filter
$data = $this->input->post(); // returns all POST items without XSS filter



how to get all post data - El Forum - 01-29-2012

[eluser]kanjimaster[/eluser]
Sweet. That's one less file to add to each project. Thanks for the update.


how to get all post data - El Forum - 09-15-2012

[eluser]minnieso[/eluser]
Hummm..