Transcript chapter10

10
Hidden Fields
and E-Mail
CGI/Perl
Programming
By Diane Zak
1
10
Objectives
• In this chapter, you will:
• Create a form using a CGI script
• Include a selection list in a form
• Use a hidden field to pass information
from one script to another
• Send an e-mail message using a script
2
10
Introduction
• When a browser connects to a
web server:
– Connection or session is opened
– After the server has fulfilled the
request, the connection is closed
• Server maintains no information about
the session
– Will often need to have the server
remember information about a
session
• Hidden fields
• Cookies
3
The Sun Travel
Web Pages
10
4
The Sun Travel
Web Pages
10
• Selection list:
– HTML form element
– List box from which
user can select a
value or values.
• Reasons to use:
– Less typing for user
– Helps maintains data
integrity
5
Planning the
sun1.cgi Script
10
6
10
Coding the sun1.cgi Script
7
10
Creating a Hidden Field
in a Script
• Like other form elements, a hidden
field has both a key and a value
– Can be used to save information that
would normally be lost when the
connection to the server is closed
– Not visible on the form
• However visible in form’s source code
– Syntax:
• print “<INPUT TYPE=hidden NAME=name
VALUE=value>\n”;
8
Completed
sun1.cgi Script
10
9
Planning and Coding
the sun2.cgi Script
10
10
Using a Script to
Send E-Mail
10
• Need the Mail::Sendmail module
installed
– whereis Sendmail.pm (UNIX)
– Start  Search  Sendmail.pm
(Windows)
11
Using a Script to
Send E-Mail
10
• Procedure for using the Mail::Sendmail
module:
– 1. Enter use Mail::Sendmail;
– 2. Create a hash and assign a value to the
appropriate keys below
– 3. Enter sendmail (hash);
key
value
To
Recipient’s e-mail address
From
Sender’s e-mail address
Subject
Message subject
Smtp
Sender’s SMTP server
Message
Message to send to recipient
12
Completed
sun2.cgi Script
10
13
10
Summary
• A selection list is a list box from which
the user can select a particular value or
set of values.
• You can use a hidden field to pass
information from one CGI script to
another.
• Like other form elements, a hidden key
has a key and value.
– key and value are passed to the server like
any other form element
14
10
Summary
• Unlike other form elements, a hidden
field does not appear on the form.
• You can use the Mail::Sendmail module
to send e-mail from a script.
– Command: use Mail::Sendmail;
• Enter the information you want to send
by e-mail in a hash.
– keys: To, From, Subject, Smtp, and Message
– Send e-mail: sendmail (hash);
15