I have two seperate perl documents:
- mailcheck.pl
- loggingpage.pl
Mailcheck prints out a form in html where the user can put in her/his email and checks if the input is a valid email address. Then it calls upon the loggingpage.pl which saves the email in a logfile and gives out information to the user if the email address was successfully stored.
These are the two documents:
mailcheck.pl:
#!/usr/bin/perl use strict; use warnings; print "Content-type: text/html\n\n"; print <<HTML; <html> <head> <title>Mailcheck</title> </head> <body> <form name="ec" action ="./loggingfiles.pl" method="get"> Email: <input type="text" name="email"> <br> <input type="button" value="Pruefen" onclick="javascript:emailcheck();"> </form> <script language="javascript" type="text/javascript"> function emailcheck() { var emailoutline = /^[a-z0-9._%+-]+\@[a-z0-9.-]+\.[a-z]{2,4}\$\/\; var x = document.ec.email.value; if (emailoutline.test(x)) { open("./loggingpage.pl); } else { alert("Dies ist keine richtige eMailadresse!"); } } </script> </body> </html> HTML exit;loggingpage.pl:
#!/usr/bin/perl use strict; use warnings; use CGI qw(:standart); #reads the input of the form called "email" $emailinput = param('email'); #saves the email in the logfile open(my $ml, ">", "./../logs/maillog.txt") or die "Fehlermeldung"; print $ml scalar(localtime()), " Email: ", $emailinput; close($ml); #gives out information about the saving process if (...) #saving the email in the logfile succeeded { print <<HTML; <html> <head></head> <body> <script language="javascript" type="text/javascript"> alert("Your input has been saved under the following email: " + $emailinput); </script> </body> </html> HTML exit; } else #gives out warning if information was not stored right { print <<HTML; <html> <head></head> <body> <script language="javascript" type="text/javascript"> alert("Error while saving your input."); </script> </body> </html> HTML exit; }
(I know that the <<HTML (..) HTML blocks cannot have spaces in front of them - in my actual document I have edited the block the right way)
My questions are now:
a. How can I write the if-conditions when I want to see if the email got saved in the logfile?
b. I am not quite sure if the part $emailinput = param('email'); works since I was not able to try it, is it the right way to get the input of the form in mailcheck.pl or do I need to write the code differently?
For you information: - mailcheck.pl works correctly. - the saving of the email in the logfile also works fine (i tried it through defining a variable as an email and saving that into the logfile together with the current date...)