4. Forms and CGI
As we discussed briefly in Chapter 4, Forms and CGI forms are generally used for two purposes: data collection and interactive communication. You can conduct surveys or polls, and present registration or online ordering information through the use of forms. They are also used to create an interactive medium between the user and the Web server. For example, a form can ask the user to select a document out of a menu, whereby the server returns the chosen document.
The main advantage of forms is that you can use them to create a front end for numerous gateways (such as databases or other information servers) that can be accessed by any client without worrying about platform dependency. On the other hand, there are some shortcomings with the current implementation:
- The interface does not support any data types besides the general “text” type. The next HTML specification could contain other data types, such as “int,” “date,” “float,” and “url.”
- User input cannot be checked on the client side; the user has to press the Submit button and the CGI program on the server side has to make sure the input is valid.
This chapter covers:
- The HTML tags for writing forms
- How form data is sent to the server
- Examples of designing form-based CGI applications, both in Perl and other languages
4.1 HTML Tags
A form consists of two distinct parts: the HTML code and the CGI program. HTML tags create the visual representation of the form, while the CGI program decodes (or processes) ...
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