บทนำ
ปุ่ม Submit จะส่งข้อมูลฟอร์มไปยัง URL ที่ระบุในแอตทริบิวต์ action ของ <form>
ตัวอย่างโค้ด
<!DOCTYPE html>
<html>
<body>
<form action="/new.php">
Student Name:<br>
<input type="text" name="sname"><br>
Student Subject:<br>
<input type="text" name="ssubject"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
แอตทริบิวต์สำคัญของ <form>
| แอตทริบิวต์ | คำอธิบาย |
|---|---|
action | URL ปลายทางที่รับข้อมูล (จำเป็น) |
method | GET (ค่าเริ่มต้น) หรือ POST |
enctype | ประเภท encoding: application/x-www-form-urlencoded (default), multipart/form-data (สำหรับไฟล์), text/plain |
target | _blank, _self, _parent, _top, framename |
วิธีอื่น: formaction บนปุ่ม
ใช้ <button type="submit" formaction="/other.php"> เพื่อส่งไป URL ต่างกันจาก form หลัก