How to set up smartphones and PCs. Informational portal
  • home
  • Windows 8
  • On forms and their elements. Web forms and their elements: types and purpose

On forms and their elements. Web forms and their elements: types and purpose

One of the options for processing the form can be sending data by e-mail:

action="mailto:Ad [email protected] ver.domain"

Using the method attribute, you can specify the protocol for sending data to the server. GET protocol is used by default, but in most cases it does not satisfy developers, so the POST protocol is more often used.

The enctype attribute allows you to specify how the form content is to be encoded.

Fill out the form different users, so it has an attribute that allows you to define a list of valid encodings:

accept-charset="charset list"

You can also define a list of valid data types:

accept="list of data types"

Most forms are provided with buttons that allow you to clear (reset" the form or confirm (submit) the correctness of its filling and send data. To determine the script programs that should be executed after the specified user actions, there are two event attributes onsubmit and on reset.

Standard attributes: id, class, lang, style, dir, title, target, event attributes

This element allows you to create various parts of the form, such as checkboxes, radio buttons, input fields. The element does not have an end tag, since all parameters are set using attributes.

The type of an element is determined by the type attribute:

Type="text" - creating an input field in which you can automatically place arbitrary text using the value attribute;

Type="password" - creating a field for entering a password, and the entered information is displayed with asterisks;

Type="checkbox" - create a checkbox;

Type="radio" - definition of one radio button. Multiple INPUT elements must be used to create a radio button group. Here is an example of a group of three radio buttons:

Switches

The checked attribute specifies which of the radio buttons should be selected by

by default. On fig. 4.4 shows the appearance of this group of switches.

Fig.4.4. Switch group

Type="button" - creating a custom button;

Type="submit" - creating a button that, when clicked, confirms the input of information into the form. The value attribute is used to define the label on the button;



Type="reset" - also a button, but for canceling data entry into the form;

Type="image" - creating a button with an image. To indicate graphic file the src attribute is used. align attribute designed for positioning a button with a pattern. Attribute values ​​have already been mentioned several times:

bottom, left, middle, right, top. Use this attribute for this case I don't recommend it as not all browsers support it;

Type="file" - File selector to attach to the form. The user is prompted to write the file name in the input field. In addition, the browser automatically creates a Browse button next to the input field, which allows you to launch the standard (for operating system) file selection dialog;

Type="hidden" - element hidden from the user. Such elements are used to include some fixed information in the form dataset. In essence, this is the definition of a variable name and its value.

The rest of the attributes are needed to define the properties of the element. Many of them are required because they provide processing of form data on the server side.

The name attribute must be present on all INPUT elements except for the accept and reset buttons. The value of this attribute determines the name of the form field, that is, the block of data entered in this field. The server program by this name can extract the necessary data.

We already know the scope of the value attribute. The attribute value specifies the default value for the input field or defines the label on the button.

Above, we showed you how to create a group of radio buttons using the checked attribute. In exactly the same way, this attribute can be used for checkboxes. Its presence indicates that the checkbox should be checked by default. Unlike radio buttons, any number of checkboxes can be checked at the same time.

The size attribute allows you to set the length of the input field. The length is expressed in characters, but this value can only be given approximately. To place a certain number of characters in the input field, you will need to select the attribute value. However, no one can guarantee that all browsers will provide the required line length, and not less. Thus, the length of the input field must be chosen with a margin.

The maxlenght attribute can be used in two ways. First, he defines maximum length string that can be written in the input field. Secondly, it can be used to limit the size of the file attached to the form.

The readonly attribute allows you to create an element that is not editable.

The usemap attribute (see the Pictures and Maps section above) can be used if a map is being created on the form.

Just like in FORM, in INPUT element you can specify the accept attribute.

Valid general attributes: accesskey, tabindex, readonly, disabled.

Standard attributes: id, class, lang, title, dir, style, event attributes.

Using the FORM and INPUT elements, you can create an object that will replace the similar object created from the ISINDEX element. The code below performs the same function as the code for the ISINDEX element (see Figure 4.3):

<Р>String for entering search criteria

This element is a container for other form elements. For example, you can combine an inscription and an input field:

If the LABEL element and another element are separate, the for attribute is used, the value of which must match the value of the id attribute of the corresponding element:

One form element is created for each LABEL element. Sometimes it is convenient to distribute elements among the cells of the table, thereby ensuring the alignment of the data in the form.

Standard attributes: accesskey, id, class, lang, dir, title, style, event attributes.

A form is a page element with which the user can submit data to the server. An example of an HTML form is an authorization form on a website. The user enters a username and password, presses a button, and this data is sent to the server and processed there. The form does not participate in data processing in any way, this is done by the program located on the server, and the form only sends data to it.

Since forms are related to the work of the server, when studying this topic, some things may not yet be clear. But you still need to study the forms. First, because individual form elements can exist without being sent to the server. And the data in them can be used when running various scripts. Secondly, if you are going to develop further in the field of creating websites, then you will need to know at least one server-side language, such as PHP. And when you learn it, you will need to know HTML so as not to be distracted by it.

Form creation

HTML Form is created using the tag . This tag itself does not display any input fields, buttons, or anything at all on the page. There are other tags for this. A tag combines them into one form and sends data from them to the server.

Consider a few important tag attributes . The form can be given a name. This is done with the name attribute. The form name must be unique. It is used to find the form when running scripts.

The action attribute specifies a file that runs on the server and receives data from the form. The value of the attribute is the path to the file.

The method attribute sets the request method. Can take values:

method="get"

method="post"

An example HTML form:

Inside the tag

form elements are placed. Form elements are various input fields, buttons, and other ways in which the user enters information. Different tags are used to create form elements. Let's consider them in detail.

Tag

Tag may look different on the page depending on the type. Including it can create different input fields. Tag types quite a lot, so it is considered in a separate topic. In the meantime, we will create it on the page as an example. Let's add it inside the tag .

The name attribute is very important. The name of the form element is passed to the server along with the value. The data is sent to the server in the following form:

name = value

If in the above example the user enters - Andrey in the input field, then the data will be sent to the server in the form:

If the form element is not given a name, then the data from this element will not be sent to the server.

Tag used instead of element when you need to create large text fields. The text displayed as the original value is placed inside the tag. The field dimensions are set using the cols attributes - horizontal dimensions, rows - vertical dimensions. The field height can be set with the height property. All sizes are calculated based on the size of one character in a monospace font.

Table 4. Tag attributes

7. Buttons

Element creates clickable buttons. Unlike buttons created ( , , , ), inside the element .

Buttons allow users to submit data to a form, clear the contents of a form, or take some other action. You can create borders, change the background, and align text on the button.

Table 9. Tag attributes
Attribute Meaning / description
autofocus Sets the focus to the button when the page loads.
disabled Disables the button, making it unclickable.
form Points to one or more forms that this button belongs to. The attribute value is the identifier of the corresponding form.
formaction The attribute value contains the url-address of the form data handler sent when the button is clicked. Only for a button like type="submit" . Overrides the value of the action attribute specified for the element
.
formenctype Sets the encoding type of the form data before sending it to the server when clicking on buttons like type="submit" . Overrides the value of the enctype attribute specified for the element . Possible values:
application/x-www-form-urlencoded is the default value. All characters will be encoded before sending.
multipart/form-data - characters are not encoded. It is used when files are uploaded using a form.
text/plain - characters are not encoded, and spaces are replaced with a + character.
formmethod The attribute specifies the method the browser will use to submit the form. Overrides the value of the method attribute specified for the element . Specified only for buttons like type="submit" . Possible values:
get - data from the form (name/value pair) is added to the url and sent to the server. This method has limits on the size of the data sent and is not suitable for sending passwords and confidential information.
post - data from the form is added as an http request. The method is more reliable and secure than get and has no size limit.
formnovalidate The attribute specifies that form data should not be validated on submission. Specified only for buttons like type="submit" .
formtarget The attribute specifies in which window to display the result after submitting the form. Specified only for buttons like type="submit" . Overrides the value of the target attribute specified for the element .
_blank - Loads the response into a new window/tab
_self - loads the response in the same window (default)
_parent - loads the response into the parent frame
_top - loads the response in full screen
framename - Loads the response into a frame with the specified name.
name Sets the name of the button, the value of the attribute is text. Used to refer to form data after the form has been submitted, or to refer to the given button(s) in JavaScript.
type Specifies the button type. Possible values:
button - clickable button
reset - reset button, returns the original value
submit is a button for submitting form data.
value Sets the default value sent when the button is clicked.

8. Checkboxes and radio buttons in forms

Checkboxes in forms are set using the construct , and the switch - using .

Checkboxes, unlike radio buttons, can have multiple checkboxes in one form. If the checked attribute is specified for checkboxes, then when the page loads, the corresponding form fields will already have their checkboxes checked.

Element

Represents a single-line text field (Fig. 1), physical size which can be set using the SIZE attribute, and the character sequence originally entered into it using the VALUE attribute.

Rice. 1. TEXT form element

An example of using this element in HTML code is next line:

TYPE="PASSWORD"

The type is exactly the same as the previous one, except that the information entered by the user in the text field will be displayed on the screen as "*" characters to hide the text from an outside viewer.

An element that is a simple selection form that takes one of two stable states: “checked” - “not checked” (Fig. 2).

Rice. 2. CHECKBOX form element

This element operates with the so-called Boolean variables, that is, variables, each of which can take the value "TRUE" or "FALSE". Each element of the CHECKBOX form creates a logical pair of values ​​of the form "element_name-state" and passes them to the server. To set the initial state of an element (checked or not), use the CHECKED attribute.

Usage example:

The so-called radio button (Fig. 3) is used when a logical variable can take only one value out of many possible ones.

Rice. 3. RADIO form element

All RADIO elements of the same form are identified by the same NAME attribute value.

The use of radio buttons requires explicitly specifying the values ​​of the VALUE attribute; one of the buttons must be marked with the CHECKED attribute.

Usage example:

<Р АLIGN="СЕМТЕR">Please enter your age

Displays an ordinary button (Fig. 4), clicking on which leads to some server action.

Rice. 4. BUTTON form element

The NAME attribute assigns a unique name to this element, the VALUE attribute allows you to change the label displayed on the button.

Usage example:

TYPE="SUBMIT"

Defines a button, upon pressing which the data from the form is transmitted to the server. As in the previous case, the label displayed on the button is set by the VALUE attribute.

Usage example:

Creates a button that clears an incorrectly filled text form. The parameters and values ​​for this button are not sent to the server along with other form data. Usage example:

TYPE="FILE"

Generates a button on the screen, when clicked, Windows Explorer appears on the screen, allowing you to attach any file from the user's local computer to the data sent to the server. This element is mainly used in forms for sending e-mail messages from the server to organize attachments, as well as to upload images to the server. Usually, a small text field is displayed next to the button, where the name of the file being sent and the path to it on the local disk are automatically entered.

Usage example:

TYPE="IMAGE"

Creates a submit button similar to the SUBMIT element, but with a user-created graphic. Usually used in cases where the standard gray rectangular button "does not fit" into the design of the site. The URL to the image that plays the role of the button is indicated by the SRC attribute, and the element itself can contain its own attributes, similar to those used in the tag (See Lesson 5), including ALIGN, ALT, and others. The NAME and VALUE attributes are treated the same as the corresponding attributes of the SUBMIT element.

Usage example:

This element is hidden and is not displayed on the user's monitor screen.

It is used to store and transfer information about current state form: when the SUBMIT button is pressed, the HIDDEN element will form a logical pair type variables"name-value", which will be sent to the server using the HTTP protocol. HIDDEN elements provide an affordable alternative cookies - special files, in which individual settings user and allowing, for example, to restore the last state of the form when the user revisits the page containing this form.

Usage example:

However, with the tag it is possible to transfer far from all the form elements available to the web designer. For example, text fields defined by the TEXT and PASSWORD attributes are very limited in the number of characters that can be entered in these fields. If the webmaster was faced with the task of creating such text field, so that the user can enter a large number of characters, a separate tag is used

You are already familiar with the NAME attribute, which specifies the individual name of each form element. The ROWS and COLS attributes indicate, respectively, the maximum allowed number of lines of input text and characters per line. If the text typed by the user does not fit into the visible part of the text container, vertical and horizontal scroll bars appear along the edges of the field to scroll the contents of the TEXTAREA element.

Usage example:

To create a selection menu in the form (Fig. 6), the webmaster can use the tag

OPTION VALUE="(!LANG:Point N">Пункт N!}

The MULTIPLE attribute determines for the user the ability to mark not one, but several items at once from the proposed list. If this attribute is set, you can use the SIZE attribute, which determines the number of positions visible on the screen at the same time.

Usage example:

<Р АLIGN ="CENTER">Please enter your city