Solved

Perl: Formatting checkbox input in email

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

724 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