I made some time to fix your code but phdr made a better post for you to follow. I will still post my code since i made time to write it:
<?php
$nameErrorMessage = "Please enter a valid name."; //or something more friendly like "Oops! the name field has an error. Please correct the error."
$nameError = 0;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$inputName = trim($_POST["contact-name"]);
$showInputName = htmlentities($inputName, ENT_QUOTES, "UTF-8");
if (!$inputName) {
$nameError = 1;
} else {
?>
<html>
<head>
<title>Name Form</title>
</head>
<body>
<div><?php echo $showInputName; ?></div>
</body>
</html>
<?php
exit; }
}
header("Content-Type: text/html; charset=utf-8");
?>
<html>
<head>
<title>Name Form</title>
</head>
<body>
<form id="contact-form" method="post" action ="">
<div>
<label for="contact-name">Name:</label>
<input type="text" id="contact-name" name="contact-name" value="Placeholder requiring backspace" />
<?php if ($nameError) { echo $nameErrorMessage; } ?>
</div>
</form>
</body>
</html>
<?php
exit;
?>
stick with the format posted by phdr please. I didn’t have time to write it as phdr did. I have to go now. I have physical therapy for my shoulder.