10 1 Hidden Fields and 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 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 Travel Web 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 “ \n”;
10 9 Completed sun1.cgi Script
10 Planning and Coding the sun2.cgi Script
10 11 Using a Script to Send 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 to Send keyvalue ToRecipient’s address FromSender’s address SubjectMessage subject SmtpSender’s SMTP server MessageMessage to send to recipient
10 13 Completed sun2.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 from a script. –Command: use Mail::Sendmail; Enter the information you want to send by in a hash. –keys: To, From, Subject, Smtp, and Message –Send sendmail (hash);