Home Web Front-end HTML Tutorial Detailed explanation of the method attribute in the form tag

Detailed explanation of the method attribute in the form tag

May 20, 2017 am 10:23 AM

Example

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

1

2

3

4

5

<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 这两个参数。在对这些元素的值进行编码时,它们的形式如下所示:

1

<a>x=28&y=66</a>

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

1

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

Copy after login

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

1

<a href="http://www.example.com/example/program?x=28&y=66"></a>

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

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

1

<a href="http://www.example.com/example/program?x=28&y=66"></a>

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

语法

1

<a href="http://www.example.com/example/program?x=28&y=66"><form target="value"></a>

属性值

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution to PHP Fatal error: Call to a member function fetch() Solution to PHP Fatal error: Call to a member function fetch() Jun 23, 2023 am 09:36 AM

When using PHP for web application development, you will often need to use a database. When using a database, error messages are very common. Among them, PHPFatalerror: Calltoamemberfunctionfetch() is a relatively common error that occurs when using PDO to query the database. So, what causes this error and how to solve it? This article will explain it in detail for you. 1. Cause of error

BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? Mar 04, 2025 pm 12:00 PM

BinaryX's token name change: from BNX to FOUR, and then to FORM, the deep meaning behind strategic adjustments BinaryX recently changed the token symbol from $FOUR to $FORM, which has attracted widespread attention from the industry. This is not the first time BinaryX has changed its name, and its token symbol has undergone a transition from BNX to FOUR. This article will explore in-depth the strategic intentions behind this series of name change. 1. Token name change process and strategic considerations BinaryX initially launched the $BNX token based on the BNB chain in 2021 to support its Play-to-Earn (P2E) gaming ecosystem. In early 2024, in order to optimize the economic model, BinaryX divided $BNX and gradually expanded to GameF

How to use POST request method in jQuery How to use POST request method in jQuery Feb 28, 2024 pm 09:03 PM

How to use the POST request method in jQuery In web development, data interaction between the front-end page and the back-end server is often involved. Among them, POST request is a commonly used method. Through POST request, you can submit data to the backend server and obtain the corresponding return result. jQuery is a popular JavaScript library that provides a convenient way to make AJAX requests. This article will introduce how to use the POST method in jQuery for data transmission and provide specific instructions.

Can there be multiple forms in html5? Can there be multiple forms in html5? Aug 01, 2022 pm 05:28 PM

There can be multiple forms in html5. The rules allow multiple form tags to be used in the same HTML page. However, in order to prevent the backend from not recognizing it when submitting, you need to add different IDs or classes to the form. The syntax is "<from action="url" id=" id value 1">Form element</from><from action="url" id="id value 2">Form element</from>.....".

What is the tag that defines the form in html5 What is the tag that defines the form in html5 Jul 26, 2022 pm 04:26 PM

The tag defining a form in HTML5 is "<form>". The form tag is used to create an HTML form (form field) for user input to collect and transfer user information. All content in the form will be submitted to the server; the syntax "<form action="Submit Address" method="Submit Method " name="form name">form control</form>". A form can contain one or more form elements, such as input, select, and textarea.

Comprehensively organize elements related to form forms! Comprehensively organize elements related to form forms! Aug 05, 2022 am 11:45 AM

This article gives you a detailed summary of the knowledge points related to form elements in HTML. I hope it will be helpful to you!

Java method definition, calling and overloading methods Java method definition, calling and overloading methods May 16, 2023 am 09:04 AM

Definition and calling of methods. What is a method? A method is a piece of code used to complete a specific function, similar to functions in other languages. Methods are used to define the behavioral characteristics and functional implementation of the class or instances of the class. Methods are abstractions of the behavioral characteristics of classes and objects. Methods are very similar to functions in procedure-oriented programming. In process orientation, function is the most basic unit, and the entire program is composed of function calls. In object-oriented, the basic unit of the entire program is a class, and methods are subordinate to classes and objects. Method declaration format [modifier 1 modifier 2...] return value type method name (formal parameter list) {Java statement;...&hel

php记录搜索引擎蜘蛛爬行记录代码 php记录搜索引擎蜘蛛爬行记录代码 Jun 13, 2016 am 10:08 AM

php记录搜索引擎蜘蛛爬行记录代码。php教程记录搜索引擎蜘蛛爬行记录代码 center form action=setup.php method=post table align=center tr td服务器:/tdtdinput value=localhost name=server //td /tr tr td用

See all articles