Detailed explanation of the method attribute in the form tag

Y2J
Release: 2017-05-20 10:23:26
Original
3204 people have browsed it

Example

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

<form action="form_action.asp" method="get">
  <p>First name: <input type="text" name="fname" /></p>
  <p>Last name: <input type="text" name="lname" /></p>
  <input type="submit" value="Submit" />
</form>
Copy after login

Definition and usage

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

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

method attribute

The browser uses the method set by the method attribute 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 the 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 directly send all the form data in one transmission step: the browser will directly attach the data 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 that the form processing server should use to process data, whether POST or GET, in the method attribute of the

tag.

POST or GET?

If the form processing server supports both POST and GET methods, which method should you choose? Here are some rules in this regard:

If you want to get the best form transmission performance, you can use the GET method to send a small form with only a few short fields.

● Some server operating systems limit the number and length of command line parameters that can be passed immediately to applications. In this case, those with many fields or long text fields For forms, it should be sent using the POST method.

 ●  If you have little experience in writing server-side form processing applications, you should choose the GET method. If you use the POST method, you have to do some extra work in the reading and decoding methods. Maybe this is not difficult, but maybe you are not willing to deal with these problems.

●  If security is an issue, then we recommend using the POST method. The GET method places the form parameters directly in the application's URL so that they can be easily captured by network snoopers and excerpted from the server's log files. If the parameters include sensitive information such as credit card account numbers, the user's security may be unknowingly compromised. POST applications, on the other hand, have no security vulnerabilities and can at least use encryption when transmitting parameters to the server for processing as separate transactions.

 ●  If you want to call a server-side application outside the form, and include the process of passing parameters to it, you must use the GET method, because this method allows parameters such as the form to be included as part of the URL. Applications using the POST style, on the other hand, expect an additional transfer from the browser after the URL, with content that cannot be used as the content of a traditional tag.

Explicitly pass parameters

前面的一些建议也可以作为选择此种方式的一定解释。假设你有一个很简单的表单,其中只包含 x 和 y 这两个参数。在对这些元素的值进行编码时,它们的形式如下所示:

如果表单采用了 method=GET,那么用来引用服务器端应用程序的 URL 将如下所示:

http://www.example.com/example/program?x=28&y=66
Copy after login

在任何时候我们都可以创建一个传统的 标签,用它在调用带有所需参数值的表单,其形式如下所示:

唯一的问题是,分隔参数所用的 & 符号也是字符实体中的插入符号。如果在 标签的 href 属性中放入一个 & 符号,浏览器就会将其后面的字符替换成相应的字符实体。

为了防止出现这种情况,我们必须用它的实体对等物来替换 & 符号,也就是用 "&" 或 "&" 来替换。替换之后,上面的那个引用服务器应用程序的非表单示例将如下所示:

由于这样还是不能在 URL 中使用 & 符号,并且有可能在将来带来混乱,因此我们鼓励服务器设置最后也能够接受用分号作为参数分隔符。您也可以看看自己的服务器文档,了解服务器是否支持这种功能。

语法

属性值

Detailed explanation of the method attribute in the form tag

【相关推荐】

1. HTML免费视频教程

2. 带你掌握HTML中table和form表单

3. 详解html中form表单的参数和属性

4. 详解form标签中的method属性

5. 详解form表单的工作过程

The above is the detailed content of Detailed explanation of the method attribute in the form tag. 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