More than once we have seen Web pages where we were asked to enter some data in the input fields. HTML has a mechanism for getting data from the user. Naturally, this data still needs to be processed, but this is done by specialized programs. Let's look at how they interact with Web pages.
So, the user has uploaded a Web page for himself, which contains the controls for entering information. They are all combined into a common set called form. Each form has a button, by clicking on which the data entered by the user is transferred to the processing program. This program is hosted on a Web server that serves this page. Such programs can be created using a wide variety of programming technologies. What unites them is only a single order of receiving data from a Web page. Data is transferred using the Common Gateway Interface (CGI). Therefore, processing programs are often referred to as CGI applications or CGI scripts.
So, the application receives data and processes it. Then it can either send an e-mail, or perform some operation in the database, or send the user a new Web page, the possible actions are limited only by the properties of the technology and the imagination of the programmer. With the help of such programs, all kinds of registration systems, feedback systems, guest books, forums, chats operate. With their help, more branched and complex systems are created, for example, online stores.
In order to create such applications, you still need to be able to program and know the appropriate rules for creating CGI applications. As long as we do not know how to do this, we still have to use publicly available CGI scripts. But if we get these applications, then the user input form must still be done independently. In this section, we will learn how to do this.
Form delimited by tags and ... Between these tags are tags that create input controls and tags for creating normal Web page content, that is, the input controls themselves can be located in a table, which in turn is completely placed in the form. Tag does not create any displayable structure. Rather, it is intended for internal grouping of objects.
Tag
, in fact, create a container for placing information input organs. Most of these inputs are implemented using the tag ... Let's demonstrate this with a small example (Fig. 1.32).Listing 1.33
"http://www.w3.org/TR/html4/strict.dtd">
<р>Field for entering a line of text< input type="text">
Rice. 1.32. Browser window showing the result of displaying the file shown in Listing 1.33
So, in the illustration you can see that we were able to create a text input field and a button, upon clicking on which the information entered by the user will be sent to the CGI application for processing. And if we look at the listing code, we will see that both the button and the input field were created using the same tag ... Adjusting the properties of this tag is done using its many parameters, which we will now consider.
- Parameter type is perhaps the key parameter. Using its value, we can set the type of the created control. One of the following keywords is used as the value: text, password, checkbox, radio, submit, reset, file, hidden, image, button. The default is text. We'll look at these types in more detail a little later.
- Parameter name designed to set unique names for each control. Although this parameter is optional, it is highly recommended that you use it. The accompanying documentation for CGI applications must indicate how the names should be with the relevant input authorities.
- Parameter value used to specify the default value displayed for buttons and text input fields. If we use switches, then the parameter value value will not be visible to the user, but it is this value that the CGI processing application will get if the user selects the appropriate radio button.
- Parameter cheked used only for check boxes and radio buttons. It sets their initial state. If this parameter will be entered in the tag<input>, then the switch will be turned on. The parameter is used without values.
- Parameter disabled makes the control unavailable for user use. The parameter is used without values.
- Parameter readonly applies only to input organs of text password types. Using this parameter means that the data displayed in these fields cannot be changed.
- Parameter size usually specifies the size of the data entry body. But for each separate type of input organs, its action is specific.
- Parameter maxiength allows you to set the maximum possible number of characters that the user can enter in the text input fields. The parameter value is a positive integer.
- Parameter src used in cases where we create graphics-related input bodies. The value of this parameter is the URL of the graphic file that contains the displayed image.
- Parameter alt allows you to create short descriptions of the created data entry body. This description can be displayed as a small hint-tooltip when the user hovers over the given input organ.
- Parameter tabindex sets the number of the control in the sequence of all objects, moving the input focus between which is carried out by successive presses of the tabulation key.
- Parameter accesskey allows you to set a "hot key", when pressed by the user, the input focus will go to this control.
So, we looked at the parameters used in the tag ... But we already know that with this tag we can create a variety of form objects. It's time to deal with them in detail.
The objects included in the form are divided into two types - data entry organs and buttons that initiate various actions. First, let's see how we can create input organs.
One of the most common form objects is the single line input field. We saw in Listing 1.33 that it is created using the type parameter with the value text. At the same time, quite often we need to set limits on the maximum possible number of characters that the user can enter in this field. This limitation is implemented using the maxlength parameter.
There is a modification of the one-line text input field, which is designed specifically for entering secret information, for example, passwords. They display the entered text and replace it with asterisks. Such input fields are created using the following construction:
Using type checkbox allows you to create independent switches. They are all familiar squares, in which with a click of the mouse we can set and uncheck the checkboxes. This uses the value parameter. The value of this parameter will be passed to the CGI processing application if the user checks this check box.
We can also create groups of radio buttons, which are often called dependent radio buttons. In this group, the user can select and check only one radio button. Each radio button is created with a tag
Let's take an example of the rules for creating and displaying the considered information input bodies.
Listing 1.34
:! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // EN"
http: //www.w3.Qrg/TR/html4/strict.dtd ">
,
<р>Field for entering a line of text
<р>Password field
<р>Independent switch
<р>Switch groupр>
<р>Alternative 1
<р>Alternative 2