Solved

Perl: Formatting checkbox input in email

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
This article will show, step by step, how to integrate R code into a R Sweave document
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…
The viewer will learn how to dynamically set the form action using jQuery.

743 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

15 Experts available now in Live!

Get 1:1 Help Now