Yes there is. All the POST data will be in the associative array $HTTP_POST_VARS
So you can traverse the array and extract the $key/value pairs of all the associative elements.
PHP Code:
<?
while( list($key, $value) = each($HTTP_POST_VARS) )
{
echo "element $key has the value $value <br>";
}
?>
You can perform any other array function on the array $HTTP_POST_VARS -such as
count($HTTP_POST_VARS)
to tell you the number of form elements that were returned.
Another thing that I like to do when generating the form with a variable number of checkboxes with different names is to put them into an array and embed in the form a synchronized array that holds the keys.
Here is an example of what I mean:
PHP Code:
<?
// lets say this is the current set of values
// and we are going to
$currentSettings = array("foo"=>1, "bar"=>0, "zoot"=>0);
// now print out a form from which the user can
// modify the settings using checkboxes
echo '<form name="settings" method="POST" action="foo.php">';
while( list($key,$value) = each($currentSettings) )
{
echo '<input type="hidden" name="newSettingKeys[]" value="', $key, '">',
'<input type="checkbox" name="newSettingValues[]" value="1"',
$value ? 'CHECKED' : '',
'>';
}
echo '<input type="submit" value="submit"> </form>';
?>
The above should (if I haven't made too many syntax errors) produce a form like:
Code:
<form name="settings" method="POST" action="foo.php">
<input type="hidden" name="newSettingKeys[]" value="foo">
<input type="checkbox" name="newSettingValues[]" value="1" CHECKED>
<input type="hidden" name="newSettingKeys[]" value="bar">
<input type="checkbox" name="newSettingValues[]" value="1">
<input type="hidden" name="newSettingKeys[]" value="zoot">
<input type="checkbox" name="newSettingValues[]" value="1">
<input type="submit" value="submit"> </form>
Now when you process that form data in "foo.php"
PHP Code:
<?
//pack the data back up into an associative array
$newSettings = array();
for ( $i = 0; $ < count($newSettingsKeys); $i++ )
{
$key = $newSettingsKeys[$i];
$value = $newSettingsValues[$i];
$newSettings[$key] = $value;
}
?>
Bookmarks