EllisLab text mark
Advanced Search
     
how to get all post data
Posted: 05 August 2010 12:08 PM   [ Ignore ]
Avatar
Joined: 2009-04-29
94 posts

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

var_dump($_POST); 

.

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

Thanks
Arun

 
Posted: 05 August 2010 02:34 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-03-30
1303 posts

You may find this command helpful

$this->output->enable_profiler(TRUE); 

This will output every query, $_REQUEST variable, memory, time, uri. Very helpful for developing. You can using something like

$this->input->post('field_name');
//or
foreach($this->input->post() as $key => $val)
{
  
echo "<p>Key: ".$key" Value:" $val "</p>\n";
 
Posted: 06 August 2010 04:17 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2009-04-29
94 posts

I tried

var_dump($this->input->post()); 

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

 
Posted: 06 August 2010 04:59 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4422 posts

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:

$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…

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM

 
Posted: 06 August 2010 05:14 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2009-04-29
94 posts

Thanks… I have added that to my library… smile

 
Posted: 29 January 2012 08:13 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2011-09-18
61 posts

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.

<?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

$this->input->dump_post(); 

into your code.

 
Posted: 29 January 2012 11:06 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6267 posts

CI 2.1.0

$data $this->input->post(NULLTRUE); // returns all POST items with XSS filter
$data $this->input->post(); // returns all POST items without XSS filter 

 

 Signature 

Ceritfied State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 29 January 2012 01:42 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2011-09-18
61 posts

Sweet. That’s one less file to add to each project. Thanks for the update.

 
Posted: 15 September 2012 11:11 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2012-09-15
2 posts

Hummm..