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
PHP Fatal error: Call to a member function fetch()的解决方法PHP Fatal error: Call to a member function fetch()的解决方法Jun 23, 2023 am 09:36 AM

在使用PHP进行web应用开发时,很多时候会需要使用数据库。而在使用数据库时,错误提示是非常常见的事情。其中,PHPFatalerror:Calltoamemberfunctionfetch()是一种比较常见的错误,它会在使用PDO查询数据库时出现。那么,这个错误是怎么引起的,以及如何解决呢?本文将为大家详细阐述。一、错误产生原

BinaryX再次更名FORM,还给社区的FOUR即将暴涨?BinaryX再次更名FORM,还给社区的FOUR即将暴涨?Mar 04, 2025 pm 12:00 PM

BinaryX的代币更名:从BNX到FOUR,再到FORM,战略调整背后的深层含义BinaryX近期将代币符号从$FOUR更改为$FORM,引发业界广泛关注。这并非BinaryX首次更名,其代币符号曾经历BNX到FOUR的转变。本文将深入探讨这一系列更名背后的战略意图。一、代币更名历程与战略考量BinaryX最初于2021年推出基于BNB链的$BNX代币,用于支持其Play-to-Earn(P2E)游戏生态。2024年初,为优化经济模型,BinaryX对$BNX进行了分割,并逐渐拓展至GameF

jQuery中POST请求方式的使用方法jQuery中POST请求方式的使用方法Feb 28, 2024 pm 09:03 PM

jQuery中POST请求方式的使用方法在Web开发中,经常会涉及到前端页面与后端服务器之间的数据交互。其中,POST请求是常用的一种方式,通过POST请求可以向后端服务器提交数据,并获取相应的返回结果。jQuery是一款流行的JavaScript库,提供了便捷的方法来进行AJAX请求,本文将介绍如何使用jQuery中的POST方法进行数据传输,并提供具体的

html5中可以有多个form吗html5中可以有多个form吗Aug 01, 2022 pm 05:28 PM

html5中可以有多个form。在同一个HTML的页面中规则上允许可以用到多个form标签,但是为了防止提交时后台无法识别,需要给表单加上不同的ID或者class,语法“<from action="url" id="id值1">表单元素</from><from action="url" id="id值2">表单元素</from>.....”。

html5定义表单的标签是什么html5定义表单的标签是什么Jul 26, 2022 pm 04:26 PM

html5定义表单的标签是“<form>”。form标签用于创建供用户输入的HTML表单(表单域),以实现用户信息的收集和传递,form中的所有内容都会被提交给服务器;语法“<form action="提交地址" method="提交方式" name="表单名称">表单控件</form>”。form表单中可包含一个或多个表单元素,比如input、select、textarea。

Java方法method的定义、调用及重载方法Java方法method的定义、调用及重载方法May 16, 2023 am 09:04 AM

方法的定义和调用什么是方法方法(method)就是一段用来完成特定功能的代码片段,类似于其它语言的函数(function)。方法用于定义该类或该类的实例的行为特征和功能实现。方法是类和对象行为特征的抽象。方法很类似于面向过程中的函数。面向过程中,函数是最基本单位,整个程序由一个个函数调用组成。面向对象中,整个程序的基本单位是类,方法是从属于类和对象的。方法的声明格式[修饰符1修饰符2&hellip;]返回值类型方法名(形式参数列表){Java语句;&hellip;&hel

全方位整理与form表单相关的元素!全方位整理与form表单相关的元素!Aug 05, 2022 am 11:45 AM

本篇文章给大家详细整理了HTML中form表单相关元素的知识点,希望对大家有帮助!

form表单无法提交到php怎么办form表单无法提交到php怎么办Dec 01, 2022 am 09:08 AM

form表单无法提交到php的解决办法:1、打开相应的代码文件;2、修改“onload="javascript:document.form1.submit();”语句;3、将submit的name进行更改一下即可。

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

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment