I have an html form containing the usual text boxes and a checkbox. When submitted to the server the user receives both an email acknowledgement as well as an html "thank you" page, both delivered by a perl cgi script. Depending on whether the checkbox is checked or not on submission, is it possible to change the message the user receives? i.e. checkbox true, print "thank you for attending", checkbox unchecked, print "Sorry you can't make it". This would be required for both the html page and the mail back to the user.
Any help or advice with this would be very much appreciated.
KevinADC 192 Practically a Posting Shark
It will depend on how your current perl script is coded. Does it use the CGI module?
toptier 0 Newbie Poster
Hello Kevin. Thanks for taking the time.
Not using a module. Would that explain why I couldn't get a conditional to work? I'm fairly inept at perl at this stage.
Here's the script I'm using, with "attend" being the checkbox return. If "attend" isn't checked I'd like to send the user a different message to one where the user checks box. I've also set the script to send me two emails. One with collected info and the other as a Bcc of their "thank you" email.
***********************************
#!/usr/bin/perl -w
use CGI;
my $query = new CGI;
# Output the HTTP header
print $query->header ( );
my $firstname = $query->param("firstname");
my $surname = $query->param("surname");
my $attend = $query->param("attend");
my $guests = $query->param("guests");
my $barbie = $query->param("barbie");
my $comments = $query->param("comments");
my $email = $query->param("email");
open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: $email\n";
print MAIL "To: whoever\@mydomain.com\n";
print MAIL "Subject: \n\n";
print MAIL "This data was submitted through mydomain.com\n\n";
print MAIL "$input$ENV{HTTP_USER_AGENT}\n";
print MAIL "$input$ENV{SERVER_NAME}\n";
print MAIL "Received from IP:$input$ENV{REMOTE_ADDR}\n\n\n";
print MAIL "firstname\ = $firstname\n";
print MAIL "surname\ = $surname\n";
print MAIL "attend\ = $attend\n";
print MAIL "guests\ = $guests\n";
print MAIL "barbie\ = $barbie\n";
print MAIL "comments\ = $comments\n";
print MAIL "email\ = $email\n\n";
print MAIL "\n.\n";
close ( MAIL );
open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: someone\@mydomain.com\n";
print MAIL "To: $email\n";
print MAIL "Bcc: someoneelse\@theirdomain.com\n";
print MAIL "Subject: hello\n\n\n";
print MAIL "Here is the message\n\n\n";
print MAIL "\n.\n";
close ( MAIL );
print <<END_HTML;
<html>
<head>
<style type="text/css">
body {
margin: 0;
padding: 10;
background-color: #000;
background-image: url(../images/cp.gif);
background-repeat: repeat-x y;
}
hr {
width: 100%;
height: 2px;
color: #FFCC00;
}
</style>
</head>
<p align="left">
<img border="0" src="../images/header07e.gif" width="349" height="87"></p>
<hr>
<br /><br />
<p align="center"><font face=Georgia" color="#FFCC88" size="4">
Thanks for taking the time to fill in the form $firstname.</p>
//alternate message to say "Sorry you can't make it"//
</body>
</html>
END_HTML
**************************************
Is this all too hard?
Appreciate any advice.
KevinADC 192 Practically a Posting Shark
You are using a module:
use CGI;
all you have to do is check for $attend
if ($attend) {
the box was checked
do what you want here
}
else {
the box was not checked
do what you want here
}
toptier 0 Newbie Poster
Thanks a lot Kevin. It works perfectly with the email. I guess I wasn't writing my conditional correctly. Can't get it working for the html output though. I've tried with commenting out the conditional e.g.
<% if ($attend) { %>
My message here
<% } %>
<% else { %>
My alternate message
<% } %>
Please don't laugh too much!
Would I be better off pointing to alternate html pages rather than trying to do it dynamically,
or is there someway to get it working?
I appreciate you taking time over this.
Regards,
Garry (Sydney)
KevinADC 192 Practically a Posting Shark
Something along these lines should work.
#!/usr/bin/perl
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
my $query = CGI->new;
# Output the HTTP header
print $query->header( );
my $firstname = $query->param("firstname");
my $surname = $query->param("surname");
my $attend = $query->param("attend");
my $guests = $query->param("guests");
my $barbie = $query->param("barbie");
my $comments = $query->param("comments");
my $email = $query->param("email");
my $message = "This is the message if the box is not checked.";
my $thanks = "Sorry you could not attend.";
if ($attend) {
$message = "This is the message if the box is checked.";
$thanks = "Thanks for taking the time to fill in the form $firstname.";
}
open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: $email\n";
print MAIL "To: whoever\@mydomain.com\n";
print MAIL "Subject: \n\n";
print MAIL "This data was submitted through mydomain.com\n\n";
print MAIL "$input$ENV{HTTP_USER_AGENT}\n";
print MAIL "$input$ENV{SERVER_NAME}\n";
print MAIL "Received from IPinput$ENV{REMOTE_ADDR}\n\n\n";
print MAIL "firstname\ = $firstname\n";
print MAIL "surname\ = $surname\n";
print MAIL "attend\ = $attend\n";
print MAIL "guests\ = $guests\n";
print MAIL "barbie\ = $barbie\n";
print MAIL "comments\ = $comments\n";
print MAIL "email\ = $email\n\n";
print MAIL "\n.\n";
close ( MAIL );
open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: someone\@mydomain.com\n";
print MAIL "To: $email\n";
print MAIL "Bcc: someoneelse\@theirdomain.com\n";
print MAIL "Subject: hello\n\n\n";
print MAIL "$message\n\n\n";
print MAIL "\n.\n";
close ( MAIL );
print qq~
<html>
<head>
<style type="text/css">
body {
margin: 0;
padding: 10;
background-color: #000;
background-image: url(../images/cp.gif);
background-repeat: repeat-x y;
}
hr {
width: 100%;
height: 2px;
color: #FFCC00;
}
</style>
</head>
<p align="left">
<img border="0" src="../images/header07e.gif" width="349" height="87"></p>
<hr>
<br /><br />
<p align="center"><font face=Georgia" color="#FFCC88" size="4">
$thanks</p>
</body>
</html>
~;
toptier 0 Newbie Poster
Thank you Kevin. You've been a great help. Works exactly how I wanted it to. I really do appreciate your helping me out.
Regards,
Garry
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.