I am writing a PHP program with sticky form. I want to use Text area for the "comments" part, but I couldn't make it work. Can anyone help? thanks.
<html>
<head>
<title>guestbook</title>
<style type="text/css">
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
extract($_REQUEST);
$errors = array();
if(isset($_REQUEST['submit']))
{
validate_input();
if(count($errors) != 0)
{
printForm();
}
else
{
saveGuestbook($name, $email, $comments);
showGuestbook();
}
}
else if($view)
{
showGuestbook();
}
else
{
printForm();
}
?>
<?php
function validate_input()
{
global $errors;
if($_POST["name"] == "")
{
$errors['name'] = "<span class=\"error\">Enter your name.</span>";
}
if($_POST["email"] == "")
{
$errors['email'] = "<span class=\"error\">Enter your email.</span>";
}
if($_POST["comments"] == "")
{
$errors['comments'] = "<span class=\"error\">Enter your comments.</span>";
}
}
function showGuestbook()
{
$theData = file("guestbook.txt");
foreach($theData as $line)
{
$line = rtrim($line);
print("<hr>");
list($name, $email, $comments)= split("\t",$line);
print("Name: $name<br>");
print("Email: $email<br>");
print("Comments: $comments<br>");
}
print("<hr><p>Back to <a href='guestbook.php'>Guestbook Page</a></p>");
}
function saveGuestbook($n, $e, $c)
{
$fh = fopen("guestbook.txt", "a");
$nameData = $n."\t";
fputs($fh, $nameData);
$emailData = $e."\t";
fputs($fh, $emailData);
$commentsData = $c."\n";
fputs($fh, $commentsData);
fclose($fh);
}
function printForm()
{
global $errors;
print<<<FORM
<html>
<head>
<title>guestbook</title>
</head>
<body>
<h2>Please sign our guestbook.</h2>
<form action="guestbook.php" method="post" >
<p>Name: <br />
<input type="text" size="34" name="name" id="name"
FORM;
echo 'value="'.$_POST[name].'"/>';
echo $errors['name'];
print<<<FORM
<br />
<p>Email: <br />
<input type="text" size="34" name="email" id="email"
FORM;
echo 'value="'.$_POST[email].'"/>';
echo $errors['email'];
print<<< FORM
<br />
<p>Comments: <br />
<textarea rows="4" cols="23" name="Comments" id="Comments" wrap="physical"
FORM;
echo 'value="'.$_POST[comments].'"></textarea>'; // I think here is the problem
echo $errors['comments'];
print<<<FORM
<br />
<br />
<input type= "submit" name="submit" value="submit" />
<input type="reset" name="reset" value="reset" />
</form>
<h3> Or feel free to just <a href="guestbook.php?view=view">view</a> our guestbook.</h3></body>
</html>
FORM;
}
?>
</body>
</html>