#Copyright ©1999 – 2007, Vesela Maleeva. All rights reserved. PLEASE ASK PERMISSION BEFORE YOU PRINT ANYTHING. vmaleeva@hotmail.com
#Started on 26 July 2000, Guestbook
use CGI qw(:cgi-lib);
ReadParse();
print "Content-type: text/html\n\n";
#I'm calling all subs here
if ($in{'button1'})
{
$error = validate(); #here I store validete() to any var I
#like, Doesn't need be $error
if ($error)
{
print #here I could have print $error; or JS:
qq{}
}
else
{
store_data();
}
}
my $data = get_data();
print qq{
Guestbook
$data
};
sub store_data{
open(FILE,">>guestbk.dat") || print "Ooops..$!";
print FILE qq{
Name: $in{'name'}
E-mail: $in{'email'}
Message: $in{'message'}
};
close(FILE);
}
sub get_data{
open(FILE,"guestbk.dat") || print "Ooops..$!";
my @data = ;
my $data = join('',@data);
close (FILE);
return $data;
}
#I am getting the data stored to array, I could leave an array (it would
#work), or I could store it furtehr to a string
sub validate{
my $error_message='';
#string to catch error messages. If the return of the string is empty
#string - there have been no errors. Otherwise return $error_message;
unless ($in{'name'}=~ /./) #if name has at least one char
{ $error_message .= 'Please enter a name.'}
#. = means error message cat string as in: $a.='h'; is
#same as saying $a= $a . 'h';
if ($in{'email'}=~ /./)
{
unless ($in{'email'} =~ /^.+@.+\.[a-zA-Z]{2,3}$/)
{ $error_message .= 'Invalid e-mail. Please reenter.'}
}
unless ($in{'message'}=~ /./) #same as name valdiadtion
{ $error_message .= 'Please enter a message.'}
return $error_message;
}
#Copyright ©1999 – 2007, Vesela Maleeva. All rights reserved. PLEASE ASK PERMISSION BEFORE YOU PRINT ANYTHING. vmaleeva@hotmail.com