Possible Duplicate:
Adding multiple html checkboxes with the same name to URL using $_GET
I have the following code:
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('foo[]');
for(var i in checkboxes)
checkboxes[i].checked = source.checked;
}
</script>
<input type="checkbox" onClick="toggle(this)" /> Toggle All<br/>
<input type="checkbox" name="foo[]" value="bar1"> Bar 1<br/>
<input type="checkbox" name="foo[]" value="bar2"> Bar 2<br/>
<input type="checkbox" name="foo[]" value="bar3"> Bar 3<br/>
<input type="checkbox" name="foo[]" value="bar4"> Bar 4<br/>
I just want to ask how will I able to get all the values on the checkboxes that are checked using PHP?
I'm not sure I'm understanding you but here's my impression:
You need to use an input array:
<input type="checkbox" name="foo[]" value="bar1"> Bar 1<br/>
<input type="checkbox" name="foo[]" value="bar2"> Bar 2<br/>
<input type="checkbox" name="foo[]" value="bar3"> Bar 3<br/>
<input type="checkbox" name="foo[]" value="bar4"> Bar 4<br/>
Otherwise you're just assigning the last occurrence that is valid as the posted input.
If you want to process multiple boxes give each one a name ending with "[]" to create an array.
Only the values of the checked boxes will be sent to the php script:
// $_REQUEST['foo'] will return an array of the values
echo join(',', $_REQUEST['foo']);