Solved

Perl: Formatting checkbox input in email

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Input past end of file vbs script 9 81
need a quick help to fix the script logic 4 63
Convert MSI to MSM 1 49
Batch script to move disabled user accounts to different OU 5 63
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…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

943 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

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now