Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get post values when the key is unknown in CodeIgniter

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!

like image 665
GloryFish Avatar asked Nov 18 '08 19:11

GloryFish


3 Answers

foreach($this->input->post() as $key => $val)  {  echo "<p>Key: ".$key. " Value:" . $val . "</p>\n";  } 

that can be used to

like image 21
Harpreet Bhatia Avatar answered Nov 13 '22 14:11

Harpreet Bhatia


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

like image 113
Paige Ruten Avatar answered Nov 13 '22 13:11

Paige Ruten


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

like image 1
Tom Haigh Avatar answered Nov 13 '22 14:11

Tom Haigh