Chapter 6. Forms
Most
CGI programs use HTML forms to gather user input. Forms are comprised
of one or more text-input boxes, clickable radio buttons,
multiple-choice checkboxes, and even pull-down menus and clickable
images, all placed inside the <form> tag.
Within a form, you may also put regular body content, including text
and images. The JavaScript event handlers can be used in various form
elements as well, providing a number of effects such as testing and
verifying form contents.
The <form> Tag
You
place a form anywhere inside the body of an HTML document with its
elements enclosed by the <form> tag and its
respective end tag </form>. All of the form
elements within a <form> tag comprise a
single form. The browser sends all of the values of these
elements—blank, default, or user-modified—when the user
submits the form to the server.
The required action
attribute for the <form> tag gives the URL
of the application that is to receive and process the
form’s data. A typical
<form> tag with the
action attribute looks like this:
<form action="http://www.oreilly.com/cgi-bin/update" > ... </form>
The example URL tells the browser to contact the server named www.oreilly.com and pass along the user’s form values to the application named update, located in the cgi-bin directory.
The browser specially encodes the form’s data before it passes the data to the server so it doesn’t become scrambled or corrupted during the transmission. It’s up to the server to decode the parameters or pass ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access