แอตทริบิวต์วิธีการแบบฟอร์ม HTML กำหนดวิธีการส่งข้อมูลแบบฟอร์มที่หมายถึงส่งเป็นตัวแปร URL หรือส่งเป็นธุรกรรม HTTP โพสต์
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
<form method=”get | post”></form>
ที่นี่ รับ ส่งข้อมูลแบบฟอร์มเป็นตัวแปร URL และ โพสต์ ส่งข้อมูลแบบฟอร์มเป็นธุรกรรมการโพสต์ HTTP
ให้เรามาดูตัวอย่างของ HTML Form method Attribute−
ตัวอย่าง
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
text-align: center;
}
input {
width: 315px;
display: block;
margin: 1rem auto;
border: 2px solid #fff;
padding: 8px;
background: transparent;
border-radius: 20px;
outline: none;
}
::placeholder {
color: #000;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 20px;
width: 330px;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
</style>
<body>
<h1>HTML Form method Attribute Demo</h1>
<form action="/action_page.php" method="get">
<input type="text" name="firstname" placeholder="Enter First Name">
<input type="text" name="lastname" placeholder="Enter Last Name">
<input type="submit" value="SUBMIT" class="btn">
</form>
</body>
</html> ผลลัพธ์

ป้อนรายละเอียดแบบฟอร์มแล้วส่งแบบฟอร์มโดยใช้ปุ่ม "ส่ง" เพื่อสังเกตวิธีการทำงานของแอตทริบิวต์ method
