I have a simple php script that handles form data. In the form I have several checkboxes, and when those are checked, the form contains "on" as a value.
For the remainder of the script, I need to have the string "1" instead of "on", but I can't change it for some reason.
Here is the script:
$posted=$_POST;
foreach ($posted as $key=>$val) {
if ($val == "on") {
$posted[$key] = "1";
}
}
// The $_POST parameters
echo 'The $_POST parameters:';
echo '<pre>';
var_dump($_POST);
echo '</pre>';
// The $posted parameters after conversion
echo 'The $posted parameters (after \'conversion\'):';
echo '<pre>';
var_dump($posted);
echo '</pre>';
And the output:
The $_POST parameters:
array(3) {
["id"]=>
string(6) "142892"
["help"]=>
string(2) "on"
["vm"]=>
string(2) "on"
}
The $posted parameters (after 'conversion'):
array(3) {
["id"]=>
string(6) "142892"
["help"]=>
string(2) "on"
["vm"]=>
string(2) "on"
}
$_POST = json_decode(file_get_contents("php://input"),true);
all the time.