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.
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):
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
Tag
Tag
is a pair. Inside it, you can mark the text, which will immediately be in the input field. The user can delete it if they wish.
Tag
If a list item has a selected attribute, then that item is selected by default. You don't need to set any value for this attribute, you just need to specify it in the tag.
If the height of the list is not specified, then the list is one line high. The height is changed using the size attribute. The appearance of the list depends on its height. If the list is one line high, then it looks like a drop-down list. If the height is more than one line, then the list is displayed as a block. The width of the list is the width of the largest item. It can also be changed with CSS.
Let's change the height of the list. See how this will change its appearance.
But in this form it is just a text tag. The main function of the tag
The value attribute contains the text that is displayed on the button.
When the button is clicked, the file that is specified in the action attribute of the tag is launched on the server
. This file receives the data from the form.
autofocus
Any form element can have the autofocus attribute set. It does not need to be given a value, it is simply set in the tag. An element that has this attribute set becomes the focus when the page is loaded. The attribute does not work in all browsers.
Each page element can be thought of as an object that has its own properties, methods, and event handlers. Most often, events on the page are associated with a form (pressing a button, for example).
Forms in a document are represented by the Forms family. Named forms can be referred to directly by name: forms.MyForm.property or MyForm.property.
maxLength - Returns the maximum length of a string.
defaultValue - returns the initial value of the element, set in the tags.
Methods:
select() - selects the input area of the specified form element.
Developments:
OnChange - the content of the object has been changed. The end result is checked. That is, during the editing process, changes could be made and then deleted. If the initial state of the field is equal to the final state, then the event is considered not to have occurred.
OnSelect - a part of the text has been selected.
CheckBox element, Radio.
Properties:
checked - check the current state of the checkbox. True - installed, False - disabled.
defaultChecked - Returns the element's original value, as set in the tags.
Select element.
Properties:
options is an array of options of the option object.
selectedIndex - returns the index of the selected item.
selected - Returns a boolean indicating the current state of the option in the object.
defaultSelected - returns a boolean value - the initial value of the element, set in the tags.
index - returns the index of the element.
Developments:
OnChange - the content of the object has been changed.
(horizontal rule) defines horizontal line, which inserts a line break before and after itself and takes up the entire available width. Such a line will be useful when separating a thematic introduction from the main text, for example, a scene change in a story or a transition to additional information within the reference section.
Some HTML elements that may be present inside BODY tag, are called "block-level" elements, while others are "inline" (also called "text-level" elements).
Content Model
Block-level elements can contain inline elements and other block-level elements.
Inline elements can only contain data and other inline elements. Inherent in this structural difference is the idea that block elements create "bigger" structures than inline elements.
Formatting
By default, block-level elements are formatted differently than inline elements. Typically, block-level elements start on a new line, while inline elements do not.
Grouping elements: DIV and SPAN elements
Start tag: required, End tag: required
The DIV and SPAN elements, along with the id and class attributes, provide a general mechanism for adding structure to documents. These elements define inline information (SPAN) or block-level information (DIV), but do not impose any other expressions to represent the context.
Generic attributes can be used for almost any HTML tag. Therefore, they are distinguished in separate group to avoid numerous meaningless repetitions.
access key
Allows you to jump to a text field using some keyboard shortcut with a letter or number specified in the attribute. Browsers use various combinations keys..
Specifies one or more class names to associate an element with styling. If several classes are specified, they are listed separated by a space. The class name can contain letters(A-Z, a-z), numbers (0-9), hyphen (-), and underscore (_), the first character must be a letter. contenteditable
Specifies whether the content of the element can be edited or not. Possible values: "true", "false". The value "true" can be omitted at all (contenteditable).
Context menu
Sets context menu for the element. The value of the attribute is the ID of the menu created using the tag
prefix data- is removed;
the hyphen before the letter is removed, and the letter after it becomes capital;
other hyphens remain unchanged.
For example, the data-number-of-users attribute is mapped to the numberOfUsers variable.
Specifies the direction in which text is displayed. Possible values:
ltr - from left to right,
rtr - right to left.
Draggable
Indicates whether the element can be dragged with the mouse or not. Possible values: "true", "false".
The element is hidden, i.e. it is not displayed on the page, but is available through scripts.
The hidden attribute does not work in Safari, Android, iOS.
The element ID that is used to refer to the element through scripts. Identifier - unique name of the element, i.e. in the code of the document should occur only once. The identifier can contain Latin letters (A–Z, a–z), numbers (0–9), hyphens (-) and underscores (_), the first character must be a letter. In HTML5 id can also be used to link to a specific location on a Web page.
The language of the element's content.
spell check
Specifies whether or not to check spelling and grammar in the text. Possible values: "true", "false". The value "true" can be omitted at all (spellcheck). The result will be visible only for form fields And
, as well as for elements with the contenteditable attribute set.
The element's internal styles.
tabindex
Determines how the form receives focus when navigating between elements using the Tab key. Possible value is any integer positive number. Elements that do not have a tabindex attribute are navigated to after all "numbered" elements in the order they are specified in the code.
The pop-up text that appears when the mouse pointer hovers over the element.
Style sheets. Selectors
Style sheets.
Style is everything that defines the appearance of an HTML document when it is displayed in a browser window: fonts, colors, positioning, and so on.
Cascading Style Sheets are simple technology attaching styles to HTML documents. A style sheet is a template that controls the formatting of tags in a document. It is a set of display rules.
Any cascading style sheet rule consists of two parts: a selector and a definition. Every HTML element represents a possible CSS selector. The properties of the selector determine the style of the document for which it is defined.
Selector types:
Usual.
Selector ( definition}
The definition consists of two parts: a property and its value, separated by a colon. The purpose of the property is clear from its name.
class selectors.
selector.class ( definition}
In CSS, class selectors can be used to describe own styles for different classes of the same elements.
Classes can also be declared without being explicitly bound to specific elements.
Classes can also be declared without explicitly binding them to specific elements.
ID selectors.
#ID (definition)
ID is an individually named style. With it, you can create stylistic exceptions among elements of the same class. Identifiers are used primarily to give one or more elements of the same class individual properties.
context selectors.
selector selector ( definition}
Contextual selectors are combinations of several ordinary selectors. The style is set only by the element in the given sequence depending on the cascading order.
To give multiple elements same properties selectors are listed separated by commas.
HTML Forms are controls that are used to collect information from website visitors.
Web forms consist of a set of text fields, buttons, lists, and other controls that are activated by a mouse click. Forms technically pass data from the user to the remote server.
Web programming languages are used to receive and process form data, such as PHP, Perl.
Before the advent of HTML5, web forms were a collection of several elements , ending with a button . It took a lot of effort to style forms in different browsers. In addition, the forms required the use of JavaScript to validate the entered data, and were also deprived of specific types of input fields for specifying everyday information such as dates, addresses Email and URLs.
HTML5 Forms solved most of these common problems thanks to the presence of new attributes, providing the ability to change the appearance of form elements by CSS3.
Rice. 1. Improved Web Forms with HTML5
Creating an HTML5 form
1. Item
The basis of any form is the element
...
. It does not provide input as it is a container, holding all the controls of the form together − fields. The attributes of this element contain information that is common to all form fields, so fields that are logically combined must be included in one form.
Table 1. Tag attributes
Attribute
Meaning / description
accept-charset
The attribute value is a space-separated list of character encodings, which will be used to submit the form, for example,
.
action
Required attribute, which specifies the url of the form handler on the server to which the data is submitted. It is a file (for example, action.php) that describes what to do with the form data. If the attribute value is not specified, then after reloading the page, the form elements will take on the default values. In case all work will be done on the client side JavaScript scripts, the action attribute can be set to # . You can also make sure that the form filled out by the visitor comes to your mail. To do this, you need to make the following entry:
autocomplete
enctype
Used to indicate MIME-the type of data sent with the form, for example, enctype="multipart/form-data" . Specified only if method="post" . application/x-www-form-urlencoded is the default content type, indicating that the submitted data is a list of URL-encoded form variables. Space characters (ASCII 32) will be encoded as + , and special characters such as ! will be encoded in hexadecimal form as %21 . multipart/form-data - used to submit forms containing files, non-ASCII data and binary data, consists of several parts, each of which represents content individual element forms. text/plain - indicates that plain (non-html) text is being passed.
method
Specifies how form data is submitted. The get method sends data to the server via address bar browser. When forming a request to the server, all variables and their values form a sequence like www.anysite.ru/form.php?var1=1&var2=2 . Are variable names and values appended to the server address after the sign? and are separated by & . Everything Special symbols and letters other than Latin are encoded in the format %nn , the space is replaced by + . This method should be used if you are not transferring large amounts of information. If a file is supposed to be submitted along with the form, this method will not work. The post method is used to send large amounts of data, as well as confidential information and passwords. The data sent using this method is not visible in the URL header because it is contained in the body of the message.
name
Sets form name, which will be used to access form elements via scripts, for example, name="opros" .
novalidate
Disables validation in the form submit button. Attribute is used without a value
target
Specifies the window to which the information will be sent: _blank - new window _self is the same frame _parent - parent frame (if it exists, if not, then to the current one) _top is the top-level window in relation to the given frame. If the call is not from a child frame, then to the same frame.
2. Grouping form elements
Element
is designed to group elements related to each other, thus dividing the form into logical fragments.
Each group of elements can be given a name using the element