•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 456,507 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,666 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums
Views: 1555 | Replies: 6 | Solved
![]() |
•
•
Join Date: Sep 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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.
Any help or advice with this would be very much appreciated.
•
•
Join Date: Sep 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
You are using a module:
use CGI;
all you have to do is check for $attend
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
}•
•
Join Date: Sep 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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)
<% 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)
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>
~;![]() |
•
•
•
•
•
•
•
•
DaniWeb Perl Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- embedding a cgi script into a html document (HTML and CSS)
- CGI script gathering browser info (C++)
- Formmail cgi script (Perl)
- guestbook cgi script won't return reply page???? (Perl)
- another newbie with alot of redhat and apache server Q'S (Linux Servers and Apache)
- simple cgi script issue (Python)
- My CGI Script gives me this error...What am I missing? (Perl)
Other Threads in the Perl Forum
- Previous Thread: Use of uninitialized value in concatenation
- Next Thread: Soap <-> .net


Linear Mode