You can read the raw post data. For example:
<fieldset>
<legend>Data</legend>
<?php
$data = file_get_contents("php://input");
echo $data."<br />";
?>
</fieldset>
<fieldset>
<legend>Form</legend>
<form method="post" action="formtest.php">
<input type="checkbox" value="val1" name="option"/><br />
<input type="checkbox" value="val2" name="option"/><br />
<input type="submit" />
</form>
</fieldset>
Check both boxes and the output will be:
option=val1&option=val2
Here's a live demo. All you have to do then is to parse the string yourself, into a suitable format. Here's an example of a function that does something like that:
function parse($data)
{
$pairs = explode("&", $data);
$keys = array();
foreach ($pairs as $pair) {
list($k,$v) = explode("=", $pair);
if (array_key_exists($k, $keys)) {
$keys[$k]++;
} else {
$keys[$k] = 1;
}
}
$output = array();
foreach ($pairs as $pair) {
list($k,$v) = explode("=", $pair);
if ($keys[$k] > 1) {
if (!array_key_exists($k, $output)) {
$output[$k] = array($v);
} else {
$output[$k][] = $v;
}
} else {
$output[$k] = $v;
}
}
return $output;
}
$data = "foo=bar&option=val1&option=val2";
print_r(parse($data));
Outputs:
Array
(
[foo] => bar
[option] => Array
(
[0] => val1
[1] => val2
)
)
There might be a few cases where this function doesn't work as expected though, so be careful.