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
FORM Element and Some Attributes
• Syntax
– ACTION=URI (form handler)
– METHOD=[ get | post ] (HTTP method for submitting form)
• GET is the default; form contents are appended to the URL
• POST form contents to be sent as payload
– ENCTYPE=ContentType (content type to submit form as)
• Defaults to application/x-www-urlencoded which returns name/value pairs, separated by &, spaces replaced by + and reserved characters (like #) replaced by %HH, H a hex digit
– ACCEPT-CHARSET=Charsets (supported character encodings)
– TARGET=FrameTarget (frame to render form result in, in HTML4)
(a browsing context name or keyword, in HTML5, such as _self,
_blank, _parent, _top, iframename)
– ONSUBMIT=Script (form was submitted)
– ONRESET=Script (form was reset)
– AUTOCOMPLETE (HTML5 ONLY) values completed by browser https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
Copyright © Ellis Horowitz 1999-2022 CGI 4
Tag
• Used inside
to check that form elements are being properly sent to the server
Copyright © Ellis Horowitz 1999-2022 CGI 14
Browser Output of Text Widgets Example
Copyright © Ellis Horowitz 1999-2022 CGI 15
Query Results for Text Widget Example
Copyright © Ellis Horowitz 1999-2022 CGI 16
Example of
Copyright © Ellis Horowitz 1999-2022 CGI 17
Browser Output of Checkbox Example
Copyright © Ellis Horowitz 1999-2022 CGI 18
Query Results of Checkbox Example
Copyright © Ellis Horowitz 1999-2022 CGI 19
Example of
Copyright © Ellis Horowitz 1999-2022 CGI 20
Browser Output of Radio Buttons
Copyright © Ellis Horowitz 1999-2022 CGI 21
Query Results for Radio Buttons Example
Copyright © Ellis Horowitz 1999-2022 CGI 22
Example of Multiline Input Areas
Multiline Inputs
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
Example of
Browser Output of
Query Results for
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)
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