If you want PHP to process the form, a PHP file must be invoked (not the text file you want to write to, that comes later). In the PHP file, POST and GET logic must be separated; a GET request will show the form, a POST request will invoke a handler and write to your text file.
<html><!-- Common header for GET and POST responses-->
<head>
<title>Write a File</title>
</head>
<body>
<?php // enter PHP Parsing mode
if (!$_POST) { //no POST has occurred, show the form
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="text" name="name">
<input type="submit" value="scrivi sul file">
</form>
<?php
} else { // a form *has* been POSTed
?
// sanitize the var $_POST['name'] with a basic filter
$A = filter_input(INPUT_POST,'name',FILTER_SANITIZE_STRING);
// append the sanitized input to our text file
$fp = file_put_contents('prova.txt', $A, FILE_APPEND);
// give feedback to the user
if ($fp) {
echo "File written successfully";
} else {
echo "Problem writing file.";
}
}
//escape from PHP mode
?>
<!-- this is a common footer for both GET and POST responses -->
</body>
</html>
1
solved PHP: get the value of TEXTBOX then pass it into a file