เราสามารถจัดการที่อยู่ไฟล์ ที่จะรับข้อมูลจาก form ผ่านการกำหนด attribute ที่ชื่อว่า
"formaction" ซึ่งจะทำหน้าที่ แทนที่ ค่าที่กำหนดใน action ของ form element ถ้ามีการ
ใช้งาน ดูตัวอย่าง โค้ดอย่างง่ายด้านล่าง
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <!doctype html><html><head><meta charset="utf-8"><title>Document</title></head> <!--ข้อมูลในฟอร์ม จะถูกส่งไปประมวลผลที่ไฟล์ post.php --><form action="post.php"> <input type="text" name="name"> <button type="submit">Send</button></form> <body></body></html> |
แต่สมมติว่า เรามีปุ่มส่งข้อมูลอีกปุ่ม อยู่ในฟอร์มเดียยวกัน และไม่ต้องการส่งไปใช้งานที่ไฟล์ post.php
อยากส่งไปที่ไฟล์ reply.php เราก็สามารถกำหนด formaction attribute และระบุ url หรือไฟล์ที่ต้องการ
ได้ดังนี้
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <!doctype html><html><head><meta charset="utf-8"><title>Document</title></head> <!--ข้อมูลในฟอร์ม จะถูกส่งไปประมวลผลที่ไฟล์ post.php --><form action="post.php"> <input type="text" name="name"> <button type="submit">Send</button> <button type="submit" formaction="reply.php">Reply</button></form> <body></body></html> |
สำหรับ formaction จะสามารถใช้งานได้ใน HTML5 โดยกำหนดในไฟล์ที่มี <!doctype html>
และการใช้งาน จะใช้ได้กับแท็ก ดังนี้
1 2 3 | <input type="submit" formaction="reply.php" value="Reply"><button type="submit" formaction="reply2.php">Reply</button><input type="image" formaction="reply3.php" src="img/button.png" > |
บราวเซอร์สมัยใหม่ปัจจุบันจะรองรับแล้ว