Collect $_POSTs from multiple checkbox rows

2019-02-26 03:46发布

I have a form with multiple rows of checkboxes, each with a specific id, that are being displayed using a foreach loop.

How do you grab the $_POST info from something like that? I think it is like this somehow $_POST[][], like a sub-array, but I cant figure out how to set it up:

foreach($stakholderArray as $currentEntry) {
    print "<tr class='$bgcolor'>";
    print "<td class='left'>$currentEntry[org]</td>";

    if($currentEntry['dataFound']) {  
        //if data was found for current stakeholder, display it
        print ($currentEntry['Partner']) ? '<td><input type ="checkbox" checked ="checked" /></td>' : '<td><input type ="checkbox"  /></td>';
        print ($currentEntry['Agreement']) ? '<td><input type ="checkbox" checked ="checked" /></td>' : '<td><input type ="checkbox"  /></td>';
        print ($currentEntry['Train']) ? '<td><input type ="checkbox" checked ="checked" /></td>'  : '<td><input type ="checkbox"  /></td>';
        print ($currentEntry['Meet'])  ? '<td><input type ="checkbox" checked ="checked" /></td>' : '<td><input type ="checkbox"  /></td>';
    }
    else {  //else...no stakeholder data, display empty columns
        print "<td><input type ='checkbox'/></td><td><input type ='checkbox'/></td><td><input type ='checkbox'/></td><td><input type ='checkbox'/></td><td><input type ='checkbox'/></td>";
        print "</tr>";
    }## Heading ##

7条回答
聊天终结者
2楼-- · 2019-02-26 04:44

Actualy id shouldn't work. As Joseph said, form elements are sent with their names as keys. So the proper tag should be:

<input type="checkbox" name="some_name" ... />

When you send the form, you can get the data like $_POST['some_name']

If you like you can put them in an array name="somearr[someotherarr[some_name]]]" then the content will be available in $_POST['somearr']['someotherar']['some_name']

Hope that helps.

查看更多
登录 后发表回答