edge_form/index.php

34 lines
894 B
PHP

<!DOCTYPE html>
<html>
<head>
<title>Name form</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<br><br>
<center>
<form method="post" action="index.php">
Name: <input type="text" name="fname">
<input type="submit">
</form>
</center>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_POST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
// echo $name;
echo "<p align=center>Name submitted</p>";
}
}
$myfile = fopen("/var/www/name.txt", "a") or die("Unable to open file!");
fwrite($myfile, "\n". $name);
fclose($myfile);
?>
</body>
</html>