Fields in form are initially filled with spaces

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!

each input has line spaces before and after the php so as far the script is concerned there are spaces,

if you’ve got this code from a book get a new book it’s really not a good way at all and it uses obsolete tags such as things like that should be styled from a style sheet.

The validation is only checking if there is something it could be anything the email address doesn’t check for a valid email address.

Thanks. The first line of your comment did it for me. I understood I ‘hardcoded’ the spaces myself :-[

Sponsor our Newsletter | Privacy Policy | Terms of Service