CS代考 CGI 10

Forms and Common Gateway Interface
Copyright © Ellis Horowitz 1999-2022 CGI 1

• Used to create a set of pages that contain fields in which the viewer can select and supply information

Copyright By PowCoder代写 加微信 powcoder

– Introduced very early in HTML 2.0
– Allows WWW users to perform data entry
– Permit direct interaction with customers for inquiries, registration, sales of products, and services
– To create a capability requires two steps:
• Use HTML form elements to create the pages that contain the form
• Write a server-side script to process form data; this program must be placed so the WWW server can execute it
Copyright © Ellis Horowitz 1999-2022 CGI 2

Text Checkbox
Radio button Submit Reset Password
The Original Set of User Interface


Here is a 10 x 30 text area.



Here is a 2 x 20 text area.



Here is a 1 x 40 area

To submit your comments, press this button:



Copyright © Ellis Horowitz 1999-2022 CGI 24

Browser Output of Multiline Input Areas
Initial Screen
Copyright © Ellis Horowitz 1999-2022 CGI 25

Query Results of Textarea Example
Copyright © Ellis Horowitz 1999-2022 CGI 26

Tag Attributes
– MULTIPLE
• Specifies that multiple list items may be selected (whereas normally only 1 item can be selected)
• All selected values are sent to server-side script as separate name/value pairs
– HTML5 adds more attributes:
• AUTOFOCUS: drop-down list should
automatically get focus
• FORM: defines one of more forms the select fields belongs to
• REQUIRED: user is required to select a value before submitting the form
Copyright © Ellis Horowitz 1999-2022 CGI 28

Which School would you like to apply to?

What semester do you wish to start?



To submit your choices, press this button: .

To reset the form, press this button: .

Copyright © Ellis Horowitz 1999-2022 CGI 30

Browser Output of Example
Copyright © Ellis Horowitz 1999-2022 CGI 32

FIELDSET – Form Control Group
• The FIELDSET element defines a form control group.
– By grouping related form controls, authors can divide a form into smaller, more manageable parts, improving the usability problem that can strike when confronting users with too many form controls.
– The grouping provided by FIELDSET also helps the accessibility of forms to those using aural browsers by allowing these users to more easily orient themselves when filling in a large form.
• The content of a FIELDSET element must begin with a LEGEND to provide a caption for the group of controls. Following the LEGEND, FIELDSET may contain any HTML element, including another FIELDSET.
Copyright © Ellis Horowitz 1999-2022 CGI 33

Browser Output
3 Fieldsets Grouping form elements
Run through Tab order:
Mailing Address HTML 3.2 HTML 4.0
To test ACCESSKEY in Chrome use ALT + ACCESSKEY (I, O, C)
To test ACCESSKEY in Firefox use
ALT + SHIFT + ACCESSKEY
http://csci571.com/examples/html5/fieldsettest.html
Copyright © Ellis Horowitz 1999-2022 CGI 34

Fieldset Example (see next slide)


Contact Information




3 fieldsets with legends ACCESSKEY specifies a single character for giving focus
Ordering Information

Please select the product(s) that you wish to order:





Credit Card Information







Copyright © Ellis Horowitz 1999-2022 CGI 35

Purpose of the CGI
• Common Gateway Interface (CGI) is a mechanism by which programs, called scripts, can be used to create dynamic Web documents
– Scripts are placed in a server directory
often named cgi-bin
– Scripts can deliver information that is not
directly readable by clients
– Scripts dynamically convert data from a non-
Web source (e.g., DBMS) into a Web-compatible
• Current version of CGI is 1.1
• The reason for the term “common gateway” is these programs act as gateways between the WWW and any other type of data or service
• See http://www.w3.org/CGI/
Copyright © Ellis Horowitz 1999-2022 CGI 36

Basic Operation
• An executable program that can be run without being directly invoked by users
The browser issues a query, (a), which is sent to the server; the server interprets it and invokes the proper CGI script, passing it the input data, (b); output from the script is returned, (c), via the server, to the browser, (d); output may be HTML, but it may instead be a URL, which is fetched by the server
Copyright © Ellis Horowitz 1999-2022 CGI 37

Languages to Write Gateway Programs
• Any language that can produce an executable file • Some typical ones are:
– Traditional compiled languages such as C/C++ – Or interpreted languages such as:
• PHP, JavaScript, Python or Java
• Interpreted languages are often preferred as they are
– Easy to write and portable, and speed is usually not a factor
http://w3techs.com/technologies/overview/programming_language/all
Copyright © Ellis Horowitz 1999-2022 CGI 38

Anchors Are Used to Invoke CGI Scripts
• A hypertext reference can refer to:
– A remote file

– An executable script in the cgi-bin directory

– An executable script with arguments

• URLs produced by the query “bicycle tours”:
http://search.yahoo.com/bin/search?p=bicycle+tours
http://search.msn.com/results.asp?RS=CHECKED&FORM=M
SNH&v=1&q=bicycle+tours&zip=90211
Copyright © Ellis Horowitz 1999-2022 CGI 39

CGI Script Environment Variables
• Environment variables
– are a set of pre-defined dynamic values that can
affect a running program
– they are generally part of the operating
environment in which a program runs;
– UNIX (its variants) and Windows all use these as
a means of passing information about the
environment of a process
– CGI environment variables are created by the web
server and set immediately before the web server
executes a gateway script
– the CGI script can retrieve the values and use
the data they send
– CGI environment variables are defined in
https://datatracker.ietf.org/doc/html/rfc3875
Copyright © Ellis Horowitz 1999-2022 CGI 40

CGI Environment Variables
• Can be classified into two major categories: – 1. Non-request specific
– 2. Request specific
• Non-request-specific environment variables are the same for all requests:
• SERVER_SOFTWARE, the name and version of the information server software answering the request
e.g., SERVER_SOFTWARE = Apache/1.3.15
• SERVER_NAME, server’s hostname, DNS alias, or IP address, e.g., SERVER_NAME = nunki.usc.edu
• GATEWAY_INTERFACE, the revision of the CGI specification with which this server complies
• SERVER_PROTOCOL, the name and revision of the information protocol with which this request came in
e.g., SERVER_PROTOCOL = HTTP/1.0
• SERVER_PORT, the port number to which the request was sent
e.g., SERVER_PORT = 8088
Copyright © Ellis Horowitz 1999-2022 CGI 41

CGI Environment Variables (cont’d)
•Request-specific environment variables
–These variables are set depending on each request
• REQUEST_METHOD, the method with which the request was made; e.g., (GET, POST)
• PATH_INFO, the extra p

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com