Can't seem to get it to work...see my code below. The regular post contents works, but not the checkbox status.
PHP Code:
<?php
$file = fopen("formsaved.html", "w") or exit("Unable to open file!");
foreach ($_POST as $key => $value) { //run through each $_POST variable, $key as the name, $value as value
if (strpos($key,'checkbox')===0) { //if the name of that variable starts with checkbox...
if ($value==1) { //and it is checked
$$key = 'checked'; //set $$key, meaning $checkbox#, to checked
}
} //end ifs/foreach
}
//do your code below for the form, using explicit variables
//like $checkbox34
$stringData =
'<head>
</head>
<form id="form1" name="form1" method="post" action="writeform.php">
<input type="text" name="1" id="1" value="'.$_POST['1'].'"/>
<br />
<input type="text" name="2" id="2"/>
<br />
<input type="checkbox" name="checkbox1" id="checkbox1" checked="'.$$key.'"/>
<br />
<input type="submit" name="button" id="button" value="Save" />
</form>
<body>
</html>
'
;
fwrite($file, $stringData);
fclose($file);
?>
Bookmarks