Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Cách sử dụng thuộc tính formmethod trong HTML

Thuộc tính formmethod trên nút submit ghi đè method của form, cho phép nút khác nhau gửi bằng GET hoặc POST. Chỉ hoạt động với type="submit" hoặc type="image".

Ví dụ

<!DOCTYPE html>
<html>
  <head>
    <title>HTML formmethod attribute</title>
  </head>
  <body>
    <form action="/new.php" method="get">
      Tên học sinh<br><input type="text" name="name"/><br>
      Môn học<br><input type="text" name="subject"/><br>
      <input type="submit" value="Gửi (GET)">
      <input type="submit" formmethod="post" formaction="/new2.php" value="Gửi (POST đến new2)">
    </form>
  </body>
</html>

Trường hợp dùng: Một form, nhiều hành động: nút "Xem trước" (GET), nút "Lưu" (POST).