Welcome Guest, Not a member yet? Register   Sign In
how to get all post data
#1

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

[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";
}
#3

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

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

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

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

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

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

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

[eluser]minnieso[/eluser]
Hummm..





Theme © iAndrew 2016 - Forum software by © MyBB