บทนำ
แอตทริบิวต์ formaction ใช้กับปุ่ม Submit เพื่อส่งฟอร์มไป URL ต่างกันจาก action ของฟอร์มหลัก Override action ของ <form>
ตัวอย่างโค้ด
<!DOCTYPE html>
<html>
<head>
<title>HTML Formaction Attribute</title>
</head>
<body>
<form action="/new1.php" method="get">
ชื่อนักเรียน: <input type="text" name="name"><br>
วิชา: <input type="text" name="subject"><br>
<button type="submit">Submit (ไป new1.php)</button><br>
<button type="submit" formaction="/new2.php">หน้าอื่น (ไป new2.php)</button>
</form>
</body>
</html>
กรณีใช้งาน
- ปุ่ม "บันทึก" →
formaction="/save" - ปุ่ม "บันทึกและส่ง" →
formaction="/submit" - ปุ่ม "พิมพ์" →
formaction="/print" formtarget="_blank" - ปุ่ม "ดูตัวอย่าง" →
formaction="/preview" formtarget="previewFrame"
การรองรับเบราว์เซอร์
รองรับในเบราว์เซอร์สมัยใหม่ ไม่รองรับ IE9 และก่อนหน้า
คู่กับแอตทริบิวต์อื่นๆ
ใช้ร่วมกับ formmethod, formenctype, formtarget, formnovalidate ได้