The problem is that when I have javascript automatically submit the form, the php doesn't work, but when I press the submit button it works perfectly. Does anyone know what I am doing wrong?
Code is below.
<?php
echo "
<head>
<script>
function yes(){
document.sform.submit()
}
</script>
</head>
<body onKeypress='yes()'>
<form method='post' action='?' name='sform' id='sform'>
<input type='text' id='this' name='this'>
<input type='submit' id='subform' name='subform' value='subform'>
</form>
</body>
";
if ($_POST['subform']){
$page = "expage.html";
$fh = fopen($page, 'w');
$example = $_POST['this'];
fwrite($fh, $example);
fclose($fh);
echo "<script>alert('form submitted')</script>";
}
?>
Please help if you can.