Creating a form in HTML. CSS forms How to make forms in html
I am absolutely sure that while running around the Internet, you have come across various forms, for example, a registration form, a login form, a feedback form and many, many others. HTML forms.
Actually, a form consists of various input elements: text fields, text areas, radio buttons, radio buttons, buttons, and so on.
And in this article you will learn how to create absolutely any .
First create a simple one HTML page, to which add a container (tag Now let's take a look at the form. The form starts with a tag , accordingly, ends with the closing tag
. This tag has several attributes that are highly desirable to fill out. But first, let's create a simple form with tag attributes so that you can understand the purpose of each of them more clearly: Here we begin a description of the form, which has the following attributes: 1) Attribute " name". The value of this attribute means the name HTML forms. The question arises, why is this necessary? The answer is very simple: if you use not one form, but several, then in order to distinguish one form from another, you need to set different names. And the names themselves are needed in order to access forms, for example, through JavaScript. I’ll tell you a little secret, which I don’t advise you to use, but for the sake of honesty, I’ll tell you about it. In fact, forms can be easily distinguished without names, so, generally speaking, a form name is not necessary at all. But I STRONGLY I recommend giving the forms names, because it will be easier for you to understand what each form is responsible for. 2) Attribute " action". The value of this attribute is responsible for the path to the script file that will process the form. That is, it is not enough to enter data into the form, they still need to be processed accordingly, and this is exactly the path to this handler file and is found in the attribute value " action". 3) Attribute " method". It can have one of two very popular meanings: " post" And " get". This attribute determines the sending method. I will not go into details, I’ll just say that the first method is a hidden sending of data, and the second is an open one. To make it even clearer, let’s look at two transition addresses: A) http://mysite.ru/scipt/request.php b) http://mysite.ru/script/request.php?a=7&b=Michael In the first case, the user does not see what he is sending (method " post"), and in the second he actually sees the names of the variables and their values (method " get"). At the end of the article, you can try to submit the form using two different methods and make sure they are different. But for now I will say that MUCH the method is more often used post", that is, a hidden sending. This was a description of the form itself, and now you can start adding elements to the form. The first thing we'll add is a text field. Adding a text field using a tag
, or rather using the attribute of this tag " type"with meaning" text". Also, before creating a text field, it is recommended to write what kind of field it is, for example, " your name". Inside the tag write this line: Your name: Again, let's break down the attributes: 1) Attribute " type" is responsible for the type of the input element. In this case, we indicated that this is a regular text field. In the following elements we will change the value of this attribute. 2) Attribute " name" is responsible for the name of the element. Here we indicated that the name of this field firstname. 3) Attribute " value" is responsible for the default value of this field. As they say, it is better to see once than to hear a hundred times, so you better dial ( Moreover, just type it, and don’t copy it!) this text in the editor, and then look at the result in the browser. Now let's create another similar field, but not for entering regular characters, but for entering a password. That is, everything should be the same, but only the text should be hidden behind asterisks. Therefore, moving to the next line (tag Your password: As you can see, now the value of the attribute " type" is " password". The remaining attributes are the same as for a regular text field. The next element is a dropdown list. It is created a little more complicated, since here it is necessary not only to declare the creation of a drop-down list, but also to add elements to this list. Let's write, moving to the next line (I won't mention this further) the following HTML code. Select an option: Tag means the beginning of the drop-down list. The list ends with the tag
. Attribute " name" is clear because I have already explained it several times. List items are created using the tag . Attribute value " value" means what value the variable will have choice(for example, in JavaScript), that is, either choice = 1, or choice = 2, or choice = 3. Immediately after the end of the tag description what the user sees in the drop-down list is put. Again, it’s better to look in the browser, and everything will immediately become clear to you. Now let's add a text area using the tag : Write something: Here we are creating a text area with a height of 10
strings (attribute value " rows") and a width of 15
characters (attribute value " cols"). Within this paired tag, the text in the default text area is specified. Actually, there is nothing more to say here. Let's move on. The next element is a radio button. A radio button is a set of such " circles", from which you can select only one. Radio buttons are created using HTML tag
, or, more precisely, using the value " radio"attribute" type". Let's write something like this HTML code: Choose one: Here I will focus on the attribute " name", because in addition to setting a name, it has another very important feature. If you NOT If you make the names of these three radio buttons the same, they will become independent, and, therefore, you can select several options at once. To make sure of this, change the names, and then try to select several options at once, and you will immediately be convinced of my words. Therefore, one group of radio buttons must have the same attribute value " name".attribute" value" means the value of the variable " choiceradio" (again, for example, in JavaScript). Immediately after the tag description
there is a text that the user will see next to the corresponding radio button. Another element of the form are switches ( checkbox). They are created again using the tag
. Let's write the following lines: You agree to our rules: I think everything is transparent here, so I won’t explain. I advise you to just look at what it looks like in a browser. And I will say that if the checkbox is checked, then the value of the variable " terms" will " yes", if it does not stand, then the value of this variable will be "", that is, an empty string. Another element is the file selection field. Surely, you have ever uploaded files to a server and you often had to use the file name insertion field to do this. This field is created using the already boring tag
. Let's write it like this: Select file to download: 2018-06-28
Hello dear visitor! In the previous sections, we created the main elements of the site, and also considered issues related to filling the content. And now we can move on to the next rather important and extensive topic - working with HTML forms. HTML forms are the most important interaction elements that define the interactive part of a web page. Without which no full-fledged website can do. After all, it is with their help that the main exchange is carried out between the user and the server side. But at the same time, forms are quite complex interface elements, with a wide variety of functional components and text fields. Therefore, in this section we will try to consider its main elements in more detail, paying special attention to their practical application in the website being created. Moreover, issues of working with the MySQL database will also be touched upon here. Since the use of forms in our examples will be inextricably linked with their interaction with database tables. In which the data entered by users will be stored, which will be used later by the server when processing requests. A form on a web page is set by a block element
), let's write the following code:
Option 1
Option 2
Option 3
Creating HTML Forms
About HTML forms in general