search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Table of Contents
Key Points:
Example:
Common Use Cases:
Notes:
Home Web Front-end H5 Tutorial What is the formmethod attribute in HTML5?

What is the formmethod attribute in HTML5?

Aug 19, 2025 pm 06:32 PM

The formmethod attribute in HTML5 specifies the HTTP method for a button's form submission, overriding the form's method attribute; 1. It applies to

What is the formmethod attribute in HTML5?

The formmethod attribute in HTML5 is used to specify the HTTP method (such as get or post) that should be used when submitting a form from a button or input element. It overrides the method defined in the <form></form> element’s method attribute, but only for that specific button's submission.

What is the formmethod attribute in HTML5?

This attribute is typically used with <button></button> or <input type="submit"> elements that are inside a form or associated with one.

Key Points:

  • Applies to: <button></button> and <input type="submit">
  • Values: get or post (most common), though other HTTP methods like put or delete may be supported in specific contexts via spoofing.
  • Overrides: The method attribute of the parent <form></form>
  • Use case: Allows different buttons in the same form to submit data using different methods.

Example:

<form action="/submit" method="get">
  <input type="text" name="username" />

  <!-- This button will use POST instead of GET -->
  <button type="submit" formmethod="post">Submit with POST</button>

  <!-- This button uses the form's default GET method -->
  <button type="submit">Submit with GET</button>
</form>

In this example:

What is the formmethod attribute in HTML5?
  • Clicking the first button sends the form data via POST to /submit, even though the form's default method is get.
  • Clicking the second button uses the form’s default GET method.

Common Use Cases:

  • A form with both "Save Draft" (POST) and "Preview" (GET) buttons.
  • Admin interfaces where one button deletes (using post with a hidden _method field simulating delete) and another updates (using post).

Notes:

  • The formmethod attribute only works on submit buttons.
  • It must be used in conjunction with a form (either inside it or via the form attribute).
  • For get, form data is appended to the URL; for post, it's sent in the request body.

Basically, formmethod gives you fine-grained control over how individual buttons submit a form, without needing multiple forms or JavaScript.

The above is the detailed content of What is the formmethod attribute in HTML5?. 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

Undress AI Tool

Undress AI Tool

Undress images for free

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

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)