10 1 hidden fields and e-mail cgi/perl programming by diane zak

15
10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

Upload: esmond-gallagher

Post on 17-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

10

1

Hidden Fields and E-Mail

CGI/Perl Programming

By Diane Zak

Page 2: 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

Page 3: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

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

Page 4: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

10

4

The Sun Travel Web Pages

Page 5: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

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

Page 6: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

10

6

Planning the sun1.cgi Script

Page 7: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

10

7

Coding the sun1.cgi Script

Page 8: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

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”;

Page 9: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

10

9

Completed sun1.cgi Script

Page 10: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

10

10

Planning and Codingthe sun2.cgi Script

Page 11: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

10

11

Using a Script toSend E-Mail

• Need the Mail::Sendmail module installed– whereis Sendmail.pm (UNIX)– Start Search Sendmail.pm

(Windows)

Page 12: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

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

Page 13: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

10

13

Completedsun2.cgi Script

Page 14: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

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

Page 15: 10 1 Hidden Fields and E-Mail CGI/Perl Programming By Diane Zak

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);