I have a website with a guest book entry form handled by a CGI program that saves the form data to a .txt database ($in{'name'}|$in{'email'}|$in{'comments'}\n), then redirects the user to a .cgi page that displays the guest book.
The problem is when there are hard returns in the comments section (a textarea on the form): Information contained following a hard return is viewed as a new entry. How can I either remove or escape the hard returns contained in the form data?
This is the code that the viewer is redirected to, displaying the guestbook at
#!/usr/bin/perl
require "cgi-lib.pl";
print &PrintHeader;
#Open database
open(FILE,"guestbook.txt") || die "Can't find database\n";
#Store contents of database in an array
@indata = <FILE>;
#Close database
close(FILE);
#Create page with submitted reservations
print <<"PrintTag";
<html>
<head>
<title>The Wedding of David Paladino and Amber Clevenger: Guest Book</title>
<link type="text/css" href="../davidandamber/wedding.css" rel="stylesheet">
</head>
<body>
<center>
<table class="gb" cellspacing="0" cellpadding="0">
<tr>
<td class="menu" height="500px"><a href=" class="m">Welcome</a><br>
<a href=" class="m">Events</a><br>
<a href=" class="m">Accommodations</a><br>
<a href=" class="m">Registry</a><br>
Guest Book<br>
<a href=" class="m">Sign the Guest Book</a><br>
<a href=" class="m">Contact Us</a></td>
<td class="text">
PrintTag
#Use a foreach loop to process each record in the database
foreach $i (@indata)
{
#Remove hard return from each record
chomp($i);
#Split fields on pipe character
#Assign a variable name to each of the fields
($name,$email,$comments) = split(/\|/,$i);
#Add a new row to the table for each record
print "$comments<br>\n";
print " -- <a class=\"mini\" href=\"mailto:$email\">$name</a><br>\n";
print "<hr>\n";
#Close the loop
}
#Close the table
print "</td></tr></table>";
print "</center></body></html>";
#End of script
The problem is when there are hard returns in the comments section (a textarea on the form): Information contained following a hard return is viewed as a new entry. How can I either remove or escape the hard returns contained in the form data?
This is the code that the viewer is redirected to, displaying the guestbook at
#!/usr/bin/perl
require "cgi-lib.pl";
print &PrintHeader;
#Open database
open(FILE,"guestbook.txt") || die "Can't find database\n";
#Store contents of database in an array
@indata = <FILE>;
#Close database
close(FILE);
#Create page with submitted reservations
print <<"PrintTag";
<html>
<head>
<title>The Wedding of David Paladino and Amber Clevenger: Guest Book</title>
<link type="text/css" href="../davidandamber/wedding.css" rel="stylesheet">
</head>
<body>
<center>
<table class="gb" cellspacing="0" cellpadding="0">
<tr>
<td class="menu" height="500px"><a href=" class="m">Welcome</a><br>
<a href=" class="m">Events</a><br>
<a href=" class="m">Accommodations</a><br>
<a href=" class="m">Registry</a><br>
Guest Book<br>
<a href=" class="m">Sign the Guest Book</a><br>
<a href=" class="m">Contact Us</a></td>
<td class="text">
PrintTag
#Use a foreach loop to process each record in the database
foreach $i (@indata)
{
#Remove hard return from each record
chomp($i);
#Split fields on pipe character
#Assign a variable name to each of the fields
($name,$email,$comments) = split(/\|/,$i);
#Add a new row to the table for each record
print "$comments<br>\n";
print " -- <a class=\"mini\" href=\"mailto:$email\">$name</a><br>\n";
print "<hr>\n";
#Close the loop
}
#Close the table
print "</td></tr></table>";
print "</center></body></html>";
#End of script