?
Solved

Perl: Formatting checkbox input in email

Posted on 2004-04-30
1
Medium Priority
?
277 Views
Last Modified: 2013-12-25
Hi

I have a perl script that takes the user input from a form and emails it. I am trying to format the email so that only the checkboxes that are ticked are displayed in the email but i cant work out how to do this. can anyone help? Here is my script so far

#!/usr/bin/perl
use CGI;

my $q = new CGI;
my $sendmail = "/usr/sbin/sendmail -t";
my $subject  = "Subject: Confirmation of your submission\n";
my $send_to  = "To: me\@test.co.uk\n";


my $fname =  $q->param("fname");
my $lname = $q->param("lname");
my $1check = $q->param("Mechcheck");
my $2check = $q->param("Machcheck");
my $3check = $q->param("Commcheck");

#send email
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL $subject;
print SENDMAIL $send_to;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL "Name: ";
print SENDMAIL $fname;
print SENDMAIL " ";
print SENDMAIL $lname;
print SENDMAIL "\n";

close(SENDMAIL);

print $q->header;
print "Thank you. Your details have been submitted";

...and my html

<form action="send_mail.pl" method="post" name="form">
   <input name="fname" type="text" id="fname"  size="40"> </td>
   <input name="lname" type="text" size="40"></td>
   <input name="1check" type="checkbox" class="check" id="1check" value="checkbox"></td>
   <input name="2check" type="checkbox" class="check" id="2check" value="checkbox"></td>
   <input name="2check" type="checkbox" class="check" id="3check" value="checkbox"></td>
   <input type="submit" name="Submit" value="Submit" style="cursor:hand;"></td>
   <input name="Reset" type="reset" id="Reset" value="Reset" style="cursor:hand;">
</form>

Many thanks in advance

0
Comment
Question by:nicki_bee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 6

Accepted Solution

by:
sstouk earned 375 total points
ID: 10962400
Instead of
# my $1check = $q->param("Mechcheck");
# my $2check = $q->param("Machcheck");
# my $3check = $q->param("Commcheck");


Have the following:
my($i) = undef;
my(%CheckBoxName) = undef;
$CheckBoxName{1} = "Mechcheck";
$CheckBoxName{2} = "Mechcheck";
$CheckBoxName{3} = "Commcheck";

my($Checked) = undef;

for (my $i = 1; $i < 4; $i++)
{
  if (length($q->param(("$i"."check"))) > 0)
  {
   $CheckedOnly .= " Checked: $CheckBoxName{$i} ";
  };
};

#send email
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL $subject;
print SENDMAIL $send_to;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL "Name: ";
print SENDMAIL $fname;
print SENDMAIL $CheckedOnly;
print SENDMAIL $lname;
print SENDMAIL "\n";

close(SENDMAIL);

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question