views:

3106

answers:

3

CodeIgniter allows access to POSTed data via:

$this->input->post('input_name');

where 'input_name' is the name of a form field. This works well for a static form where each input name in known ahead of time.

In my case, I am loading a collection of key/value pairs from the database. The form contains a text input for each key/value pair.

I am wondering, is there a way to get an array of posted data via the CodeIgniter api?

Thanks!

+5  A: 

According to the documentation, no. I would suggest just using array_keys($_POST) to get the keys.

yjerem
Simple and straightforward. I like it.
GloryFish
+1  A: 

Surely if you have an array of keys from the database you can use that, like :

foreach ($arrayFromDb as $key => $value) {
    $newValue = $this->input->post($key);
}

Then you have the advantage that people if people submit additional fields (e.g. by modifying the form and posting it themselves) those fields will be ignored

Tom Haigh
+1  A: 
$array_db_columns = $this->db->query('SHOW COLUMNS FROM ci_props');
    $array_db_columns = $array_db_columns->result_array();
    $array_save_values = array();
    foreach ( $array_db_columns as $value )
    {
        $array_save_values[$value['Field']] = $this->input->post($value['Field']);
    }

insert :

$this->db->insert('props', $array_save_values);

update :

$this->db->where('id',$id); $this->db->update('props',$array_save_values);

poelinca