Set of form html. HTML forms. Multiline text field - tag
Hello, dear readers of the blog site. Continuing our study, we move on to consider the form and input tags with their attributes (), with which you can create a wide variety of forms for the site.
Whatever the topic and content of a particular web resource, it will most likely contain forms in one form or another: text fields, drop-down menus, various buttons or switches. By the way, in one of the publications I already talked about elements that help diversify forms.
What is the practical purpose of all the variety of possible forms? First of all, they are needed to send user-entered data to the server for the purpose of further processing using a specially created script (handler).
HTML forms - how they are created using form and input
As I said at the beginning, some kind of web form, or even several at once, must be present on any more or less developed website. To understand how important they are in the light of a web resource’s compliance with modern requirements, it is enough to give you offhand three objects that use forms based on the form and input tags, which, just by their name, leave no doubt about their necessity for a project of one direction or another:
If you follow, for example, a link to an article about creating feedback (allowing all users to send messages to the site administration), then the HTML code with a form that has an opening (
) Part:This is where form plays a vital role as it initiates the installation of the web form. It does not itself display an area on a web page, but serves as a container containing other tags.
In our case (see screenshot above), these include several input(this HTML tag is single, in other words, does not have a closing component), and also textarea, with different sets of attributes. Each of them defines its own element included in the form.
16. Autofocus(no parameters) is a logical attribute that sets focus to the field immediately when the web page loads, as a result of which you can enter data without clicking on it. Cannot be applied to input type="hidden" only.
17. Disabled(without values) - disables for the user the form element to which it was added. Most often it is used in conjunction with scripts, where conditions are specified under which an inaccessible element will be activated.
18. Form— associates the element with the form when it is located outside the container
. To link, a global id attribute is added to the form tag, and a form attribute is added to the input tag, the values of which are the same (for example, id="data" and form="data").19. Multiple(no parameters) - sets multiple choice option for the user and is only used in conjunction with type="file" and type="email".
If you use the file upload field, you can select several files from your computer at once by using the Ctrl or Shift keys. If a field for entering an email address is displayed (type="email"), then emails should be entered separated by commas.
20. Required(no values) – activates the requirement for the user to enter data. Therefore, the browser blocks the submission of the web form if a required field is left empty and displays a corresponding message about the need to fill it out.
This attribute is not used for graphic and standard buttons (type="button | image"), as well as for hidden input fields (type="hidden").
21. Size— determines the width of the text field in characters (suitable only for type elements with the parameters "email | password | search | tel | text | url"). Default value is 20 characters.
The next four attributes (22-25) for the input tag carry almost the same functionality as for , but for the sake of completeness I will briefly mention them too.
22. Maxlength— imposes a limit on the maximum number of characters that can be entered when filling out a text field. If you attempt to exceed this limit, further input will be blocked. This attribute is only applicable for text elements with type="email | password | search | tel | text | url".
23. Minlength— imposes a limit on the minimum number of characters required to be entered into the text area. If an attempt is made to send data containing fewer characters, a short message will appear indicating the need to supplement the contents of the form and information about the number of characters already entered will be provided. The terms of use are exactly the same as in the case of maxlength.
24. Placeholder— you can place a hint (it will serve as a parameter) directly in the text field, which will disappear the moment the user starts entering characters. Only for fields that are formed using parameters email, password, search, text, tel, url type attribute of the input tag.
25. Readonly(no parameters) - indicates that the text previously entered in the field is available for reading and copying only. It is usually used in conjunction with scripts, where conditions are specified that, when met, can activate this form element.
And finally, a few more attributes that complement the functionality of various form elements:
26. Pattern— as its value, reflects a regular expression on the basis of which the rules for entering information are set. In this case, it is recommended to additionally add a global title attribute, as a parameter of which you can add explanatory text to help users fill out the fields. Pattern is applied only to email, password, search, text, tel, url elements. Let's understand it with an example. Here is the code for a simplified registration form (with ):
Login Password |
For the login field (type="text"), a regular expression (5,) is specified as the pattern value, which implies the use of Latin characters, and at least five characters must be entered.
In relation to the text area for the password (type="password"), the value is set to (8,), which specifies the entry of exclusively Latin characters in any case (upper and small letters), as well as numbers, while the total number of all characters should not be less than eight.
If the specified input conditions are violated, the browser will not allow you to send data and will display an appropriate warning:
27. Src— defines the path to the image (URL, which is its value) for displaying the graphic button “image” (see the table of input type parameters above).
28. Step— sets the step for elements that provide a choice of numeric values (input type="date | datetime-local | month | number | range | tel | time | week.").
It can take any integer or fractional number as a parameter. Default step="1". To set the final input range, you can again use the min and max attributes mentioned just above. For clarity, we will include 2 elements type="number" in the test form. For the first, set step="2", and for the second, step="0,1":
Enter a value from -10 to 10: Enter a value between 0 and 1: |
29. Value— sets the value of the form element that will be passed to the handler. A name-parameter pair is sent to the server, where the name is determined by the name attribute of the input tag, and the parameter is determined by the value attribute. Moreover, for various form elements value will play different roles:
- for type="button | reset | submit" - sets the text label on the buttons;
- for type="checkbox | radio | image" - identifies each checkbox, switch or graphic button when sending and processing data on the server;
- for type="password | text" - immediately when loading the form, it displays preliminary text in the field, which can be changed or completely deleted by the user;
- for type="file" (file upload) does not apply because it does not affect this element.
Example usage for each of the above options:
Select CMS: W.P. Joomla |
Here value attribute value defines the following components of each element: displays a text fragment for the field type="text" ("Your name"), identifies each of the radio buttons ("1" and "2") set using type="radio", and also activates inscription on the button ("Submit").
An example of creating a beautiful HTML form
Next, I will try to present you with a sample web form, the code of which includes not only input type combinations with different values that form standard text fields and buttons, but also, for example, which allow you to initiate focusing on an element not only with a direct mouse click, but also by clicking on text.
Please note that to obtain a unique design, individual form components are placed in, each with sets of:
Back (max-width:350px; margin:50px auto 0; padding:20px; background:#f3ebe1; font-family:"Oswald", sans-serif;) .form-1, .form-2, .form-3 , .form-4 (padding:15px; border:4px double #909090) .form-1, .form-2, .form-3 (border-bottom:none) .form-1 input (display:block; margin- bottom:10px; width:100%).in (padding-left:40px) .in input (width:100%) ..png) no-repeat;background-position:10px 10px) ..png) no-repeat; background-position:10px 10px) .form-4 input (display:block; height:50px; font-size:24px; width:100%; cursor: pointer)
As a result, such a web form takes on the following outline:
More complete information on creating this specific form can be found at this page(by the way, there you can not only test the functionality of individual text areas by entering data into them, but also experiment with the web form by editing the HTML code and/or CSS properties, completely or partially changing its appearance).
My goal was to introduce you to the algorithm for using different values of the type attribute and the form tag to create various HTML forms on the site. I hope the task is completed. In any case, share your thoughts on this diverse topic in the comments.
Naturally, in subsequent publications I will continue to describe the main tags of hypertext markup, so do not forget to subscribe to blog updates via e-mail. Also, to reinforce this, look at another lesson by Evgeniy Popov on creating a contact form.
Description
HTML tag
While navigating through websites, the user mostly just clicks on links to navigate web pages.
But it is clear that the user sometimes needs to provide his own input fields. These types of interactions include:
- registration and login on websites;
- entering personal information (name, address, credit card information, etc.);
- content filtering (using drop-down lists, checkboxes, etc.);
- performing a search;
- downloading files.
To accommodate these needs, HTML offers interactive controls forms:
- text fields (for one or more lines);
- switches;
- checkboxes;
- drop-down lists;
- widgets for downloading;
- submit buttons.
These controls involve different tags HTML, but most of them use the tag . Because it is a self-closing element, the type of the field is determined by its type attribute: