Hello,
I am working through a book on PHP. I made a php file mailtofile3.php. I want to show a page with 3 fields to be filled. I want to check wether or not fields are filled by submitting. I almosts works, but whem I initially open the page the fields are allready filled with some spaces. I can not detect why and what the problem is. Here is my full code of the php file which should do the whole trick:
<html>
<head>
<title>Mailformulier</title>
</head>
<body>
<?php
//($_SERVER['REQUEST_METHOD']=="POST")
//$_POST["verzendbutton"]!="verzenden"
if(($_SERVER['REQUEST_METHOD']=="POST")|| !$_POST["name"]|| !$_POST["mailadres"]
|| !$_POST["reaction"])
{ //als het formulier leeg is
?>
<form action="mailtofile3.php" method="post">
<?php
if ($_POST["sendbutton"]=="submit" && !$_POST["name"])
{
echo "<font color=\"red\">Fill in youre name here!</font><br>";
}
?>
Name: <input type="text" name="name" value="
<?php
echo trim($_POST["name"])
?>">
<br>
<?php
if ($_POST["sendbutton"]=="submit" && !$_POST["mailadres"])
{
echo "<font color=\"red\">Fill in the e-mail adress here!</font><br>" ;
}
?>
E-mail: <input type="text" name="mailadres" value="
<?php
echo trim($_POST["mailadres"])
?>">
<br>
<?php
if ($_POST["sendbutton"]=="submit" && !$_POST["reaction"])
{
echo "<font color=\"red\">Fill in your message here!</font><br>";
}
?>
Your comment: <textarea cols="30" rows="4" name="reaction">
<?php
echo trim($_POST["reaction"])
?>
</textarea>
<input type="submit" value="submit" name="sendbutton">
</form>
<?php
} else
{
$message = $_POST["name"]."<br>Comment: ".$_POST["reaction"]."<br>";
echo "Your comment from the site ".$message;
echo "thanks ".$_POST["name"].", for posting!";
}
?>
</body>
</html>
Thanks for any help!