10 1 hidden fields and e-mail cgi/perl programming by diane zak
TRANSCRIPT
10
1
Hidden Fields and E-Mail
CGI/Perl Programming
By Diane Zak
10
2
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
10
3
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
10
4
The Sun Travel Web Pages
10
5
The Sun TravelWeb Pages
• 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
10
6
Planning the sun1.cgi Script
10
7
Coding the sun1.cgi Script
10
8
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”;
10
9
Completed sun1.cgi Script
10
10
Planning and Codingthe sun2.cgi Script
10
11
Using a Script toSend E-Mail
• Need the Mail::Sendmail module installed– whereis Sendmail.pm (UNIX)– Start Search Sendmail.pm
(Windows)
10
12
• 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);
Using a Script toSend E-Mail
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
10
13
Completedsun2.cgi Script
10
14
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
10
15
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);