User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Sep 2007
Posts: 4
Reputation: toptier is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
toptier toptier is offline Offline
Newbie Poster

Change output in cgi script

  #1  
Sep 25th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2006
Posts: 642
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 36
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Master Poster

Re: Change output in cgi script

  #2  
Sep 25th, 2007
It will depend on how your current perl script is coded. Does it use the CGI module?
Reply With Quote  
Join Date: Sep 2007
Posts: 4
Reputation: toptier is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
toptier toptier is offline Offline
Newbie Poster

Re: Change output in cgi script

  #3  
Sep 25th, 2007
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 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 "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.
Reply With Quote  
Join Date: Mar 2006
Posts: 642
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 36
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Master Poster

Re: Change output in cgi script

  #4  
Sep 25th, 2007
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
}
Reply With Quote  
Join Date: Sep 2007
Posts: 4
Reputation: toptier is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
toptier toptier is offline Offline
Newbie Poster

Re: Change output in cgi script

  #5  
Sep 25th, 2007
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)
Reply With Quote  
Join Date: Mar 2006
Posts: 642
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 36
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Master Poster

Re: Change output in cgi script

  #6  
Sep 26th, 2007
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>
~;
Reply With Quote  
Join Date: Sep 2007
Posts: 4
Reputation: toptier is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
toptier toptier is offline Offline
Newbie Poster

Re: Change output in cgi script

  #7  
Sep 26th, 2007
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Perl Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Perl Forum

All times are GMT -4. The time now is 3:38 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC