How to use the method attribute of the form tag in HTML? Here is an introduction to the usage of the method attribute

寻∝梦
Release: 2018-08-28 18:02:05
Original
20817 people have browsed it

This article mainly introduces the definition and usage explanation of the method attribute of the form tag in HTML, and gives a detailed explanation. There are two common questions and answers and examples of the method attribute later. Let us now Let’s take a look together

First of all, let’s take a look at the meaning of the method attribute of the form tag in HTML?

The method attribute specifies how to send form data (the form data is sent to the page specified by the action attribute).

Form data can be sent as URL variables (method="get") or HTTP post (method="post").

Let’s take a look at the explanation of the use of the method attribute in the form tag:

The browser uses the method attribute setting method to transmit the data in the form to the server for processing. There are two methods: POST method and GET method.

If the POST method is used, the browser will follow the following two steps to send data. First, the browser will establish contact with the form processing server specified in the action attribute. Once the connection is established, the browser will send the data to the server in a segmented transmission method.

On the server side, once the POST style application starts executing, the parameters should be read from a flag location. Once the parameters are read, these parameters must be modified before the application can use these form values. to decode. User-specific servers explicitly specify how applications should accept these parameters.

Another situation is to use the GET method. In this case, the browser will establish a connection with the form processing server and then send all the form data directly in one transmission step: the browser will attach the data directly to the form. after the action URL. Use a question mark to separate the two.

General browsers can transmit form information through any of the above methods, while some servers only accept data provided by one of the methods. You can specify the method (method) attribute of the

tag that the form processing server should use to process data, whether POST or GET.

Let’s look at two common questions and answers now:

1. In addition to post, what other values ​​can be attached to get?

Answer: Only post and get are possible

post: The official explanation is to transmit the data to the server through the post session. The actual thing is to submit the data.

get: Add the data in the form to the end of the URL pointed to by the action in the form of variable=value, and use "?" to connect the two, and use "&" to connect each variable; generally Used to get data from the server.

2. What is the default value of the method attribute?

Answer: The default is get, so generally we have to specify it as post

Give an example of the method attribute of the from tag:

In the following example, the form data will be appended to the URL through the method attribute:

<form action="form_action.asp" method="get">
  <p>这是第一个名字: <input type="text" name="fname" /></p>
  <p>这是第二个名字: <input type="text" name="lname" /></p>
  <input type="submit" value="Submit" />
</form>
Copy after login

The example result is as shown:

How to use the method attribute of the form tag in HTML? Here is an introduction to the usage of the method attribute

This article ends here. I have also seen the results. You should be familiar with the method attribute. If you have any questions, you can ask below

[Editor’s Recommendation]

How to write a relative path for the base tag in HTML? (Introduction to use included)

#What is the role of the HTML meta tag? Introduction to how to use html meta tag

The above is the detailed content of How to use the method attribute of the form tag in HTML? Here is an introduction to the usage of the method attribute. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template