search
HomeWeb Front-endHTML TutorialDetailed explanation of the method attribute in the form tag

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>

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

x=28&y=66

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

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

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

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

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

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

语法

<form target="value">

属性值

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
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
What is the purpose of HTML tags?What is the purpose of HTML tags?Apr 28, 2025 am 12:02 AM

HTMLtagsareessentialforstructuringwebpages,enhancingaccessibility,SEO,andperformance.1)Theyareenclosedinanglebracketsandusedinpairstocreateahierarchicalstructure.2)SemantictagslikeandimproveuserexperienceandSEO.3)Creativetagslikeenabledynamicgraphics

What are self-closing tags? Give an example.What are self-closing tags? Give an example.Apr 27, 2025 am 12:04 AM

Self-closingtagsinHTMLandXMLaretagsthatclosethemselveswithoutneedingaseparateclosingtag,simplifyingmarkupstructureandenhancingcodingefficiency.1)TheyareessentialinXMLforelementswithoutcontent,ensuringwell-formeddocuments.2)InHTML5,usageisflexiblebutr

Beyond HTML: Essential Technologies for Web DevelopmentBeyond HTML: Essential Technologies for Web DevelopmentApr 26, 2025 am 12:04 AM

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

What are boolean attributes in HTML? Give some examples.What are boolean attributes in HTML? Give some examples.Apr 25, 2025 am 12:01 AM

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values ​​need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

How can you validate your HTML code?How can you validate your HTML code?Apr 24, 2025 am 12:04 AM

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML vs. CSS and JavaScript: Comparing Web TechnologiesHTML vs. CSS and JavaScript: Comparing Web TechnologiesApr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor