I have a form written in HTML and a PHP file that should be able to generate the input into a textfile in the same dir. I tested it out before with a different simple HTML file and it worked, now I'm trying to apply it to a bigger HTML file and somehow it wont work and I cant find whats wrong with it.
feedback.html:
<html>
<head>
<script>
function myFunction()
{
alert("Your feedback has been sent! Thank you");
}
</script>
</head>
<body>
<div class="Linksediv">
<h3>Feedback</h3>
<p>Please enter your name and give us some feedback</p>
<form action="form1.php" method="post">
Name<input id="Email" size="30" type="text" name="field1"/><br/>
<textarea id="pass" type="text" name="field2" rows="4" cols="24">Please give us some feedback
</textarea>
<br/>
<input type="button" name="submit" value="submit" id="buttonOk" onclick="myFunction()" value="Show alert box" />
</form>
</div>
</body>
</html>
Form1.php
<?php
if(isset($_POST['field1']) && isset($_POST['field2'])) { //Check if fields are there in HTML file
$data = $_POST['field1'] . ' - ' . $_POST['field2'] . "\n"; //output
$ret = file_put_contents('data1.txt', $data, FILE_APPEND | LOCK_EX); //file dir for data1.txt
if($ret === false) { //check if anything was written down
die('There was an error writing this file');
}
else {
echo "$ret bytes written to file"."\n";
}
}
?>
If I press submit on my form then I'll only get a popup with the alert, and the textfile wont be written