[eluser]k2zs[/eluser]
I am working on a form where the user will select multiple checkboxes with the same name. The values will be unique ID's from another table. I want to loop through all the checkboxex and insert into a record table.
My form is built like this:
Code:
if($subquery->num_rows()>0){
foreach($subquery->result_array() as $plName) {
$data .= '
<div>- ' . $plName['plName'] . '</div>
<div><input name="plId[]" type="checkbox" value="' . $plName['plID'] . '" checked /></div>
<div style="clear:both;"></div>
';
};
and in my controller I am only looping through the post data to see if it is working. Here is my controller function:
Code:
function submit()
{
//$this->output->enable_profiler(TRUE);
foreach($_POST['plId'] as $plGrp) {
echo $plGrp['plID'];
echo '<br />';
};
}
and when I set enable_profiler to "TRUE" I see that the array is posted correctly:
Code:
$_POST['plId'] =
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 12
[9] => 10
[10] => 11
[11] => 9
[12] => 13
[13] => 14
[14] => 15
[15] => 16
[16] => 17
[17] => 18
[18] => 19
[19] => 40
[20] => 20
[21] => 21
[22] => 22
[23] => 23
[24] => 24
[25] => 25
[26] => 26
[27] => 27
[28] => 28
[29] => 29
[30] => 30
[31] => 31
[32] => 32
[33] => 33
[34] => 34
[35] => 35
[36] => 36
[37] => 37
[38] => 38
)
but if I just loop through the post data and echo the values I only get the first digit of the data in the array.
What am I doing wrong? I would eventually like to replace my echoe'd output with an insert into the database. I am using CI v2.0