Solved

Perl: Formatting checkbox input in email

Posted on 2004-04-30
1
261 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 125 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

733 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