HTML <button> formaction属性

❮HTML<button>タグ

2つの送信ボタンがあるフォーム。最初の送信ボタンはフォームデータを「action_page.php」に送信し、2番目の送信ボタンは「action_page2.php」に送信します。

<form action="/action_page.php" method="get">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname"><br><br>
  <button type="submit">Submit</button>
  <button type="submit" formaction="/action_page2.php">Submit to another page</button>
</form>

定義と使用法

このformaction属性は、フォームが送信されたときにフォームデータを送信する場所を指定します。この属性は、フォームの属性をオーバーライドしactionます。

このformaction属性は、が付いたボタンにのみ使用されます type="submit"


ブラウザのサポート

表の数字は、属性を完全にサポートする最初のブラウザーバージョンを示しています。

Attribute
formaction 9.0 10.0 4.0 5.1 15.0

構文

<button type="submit" formaction="URL">

属性値

Value Description
URL Specifies where to send the form data.

Possible values:

  • An absolute URL - the full address of a page (like href="http://www.example.com/formresult.asp")
  • A relative URL - points to a file within the current site (like href="formresult.asp")

❮HTML<button>タグ