2. WRITING A FORM-PROCESSING SYSTEM
Processing Web forms with EiffelWeb is straightforward, as EiffelWeb takes care of parsing the form and makes the visitor's input available to you in the form of Eiffel objects, instances of EiffelWeb classes and their descendants.
Here are the basic steps to process the data entered by someone (called the "visitor" in the rest of this document) who has filled a form on your Web site:
Let us build a small example. Our system will simply display the results of any HTML form as an indented list of name-value pairs. The name of the field will appear in bold face. You only need one class, the one called YOUR_FORM above - here CGI_DEMO; it can keep the inherited make as a creation procedure. Here is the class:
with execute effected as follows:
Procedure execute loops over the elements of the array fields, which holds the names of the fields. For each field it loops over the list of values for that field, which may have zero, one or more elements. Procedure generate_html_header, which like the other features used by this version of execute comes from CGI_INTERFACE, prints on the standard output the header of an HTML reply, which is necessary to avoid getting an error from the Web server.
You will have noted that this text does not contain any HTML code. This is because using EiffelWeb does not require knowing HTML; you can produce output using abstract output procedures such as put_line_break, put_basic and generate_html_header which will take care of generating the appropriate HTML output. If you do know HTML and want to generate specific output, you can do so using the class HTML_GENERATOR (see section 6).