Chương này mô tả các thuộc tính form*
khác nhau cho thành phần HTML <input>
.
Thuộc tính form
chỉ định biểu mẫu mà thành phần <input>
thuộc về.
Giá trị của thuộc tính này phải bằng với thuộc tính id của thành phần <form> mà nó thuộc về.
Một trường input bên ngoài biểu mẫu HTML (nhưng vẫn là một phần của biểu mẫu):
<form action="/action_page.php" id="form1">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="Submit">
</form>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" form="form1">
<!DOCTYPE html>
<html>
<body>
<h1>The input form attribute</h1>
<p>The form attribute specifies the form an input element belongs to.</p>
<form action="/action_page.php" id="form1">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="Submit">
</form>
<p>The "Last name" field below is outside the form element, but still part of the form.</p>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" form="form1">
</body>
</html>
Thuộc formaction
chỉ định URL của tệp tin sẽ sử lý input khi biểu mẫu được gửi.
Ghi chú: Thuộc tính này ghi đè thuộc tính action
của thành phần <form>
.
Một biểu mẫu HTML với hai nút gửi, với các hành động khác nhau:
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
<input type="submit" formaction="/action_page2.php" value="Submit as Admin">
</form>
<!DOCTYPE html>
<html>
<body>
<h1>The input formaction attribute</h1>
<p>The formaction attribute specifies the URL of a file that will process the input when the form is submitted.</p>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
<input type="submit" formaction="/action_page2.php" value="Submit as Admin">
</form>
</body>
</html>
Thuộc tính input formenctype
chỉ định cách dữ liệu biểu mẫu nên được mã hóa khi được gửi (duy nhất cho biểu mẫu với phương thức = "post").
Ghi chú: Thuộc tính này ghi đè thuộc tính enctype của thành phần <form>
.
Thuộc tính formenctype
hoạt động với các kiểu input sau: submit và image.
Một biểu mẫu với hai nút gửi. Nút đầu tiên gửi dữ liệu biểu mẫu với mã hóa mặc định, nút thứ hai gửi dữ liệu biểu mẫu được mã hóa thành "multipart/form-data":
<form action="/action_page_binary.asp" method="post">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="Submit">
<input type="submit" formenctype="multipart/form-data"
value="Submit as Multipart/form-data">
</form>
<!DOCTYPE html>
<html>
<body>
<h1>The input formenctype attribute</h1>
<p>The formenctype attribute specifies how the form data should be encoded when submitted.</p>
<form action="/action_page_binary.asp" method="post">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="Submit">
<input type="submit" formenctype="multipart/form-data" value="Submit as Multipart/form-data">
</form>
</body>
</html>
Thuộc tính input formmethod
xác định phương thức HTTP để gửi dữ liệu biểu mẫu đến URL hành động.
Ghi chú: Thuộc tính này ghi đề thuộc tính method của thành phần <form>
.
Thuộc tính formmethod
làm việc với cá kiểu input sau: submit và image.
Dữ liệu biểu mẫu có thể được gửi như các biến URL (method="get") hay như một giao thức HTTP post (method="post").
Ghi chú về phương thức "get":
Ghi chú về phương thức "post":
Một biểu mẫu với hai nút gửi. Cái đầu tiên gửi dữ liệu biểu mẫu với phương thức="get". Cái thứ hai gửi dữ liệu biểu mẫu với phương thức="post":
<form action="/action_page.php" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit using GET">
<input type="submit" formmethod="post" value="Submit using POST">
</form>
<!DOCTYPE html>
<html>
<body>
<h1>The input formmethod Attribute</h1>
<p>The formmethod attribute defines the HTTP method for sending form-data to the action URL.</p>
<form action="/action_page.php" method="get" target="_blank">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit using GET">
<input type="submit" formmethod="post" value="Submit using POST">
</form>
</body>
</html>
Thuộc tính input formtarget
xác định một tên hoặc từ khóa chỉ ra nơi để hiển thị phản hồi được nhận sau khi gửi biểu mẫu.
Ghi chú: Thuộc tính này ghi đè thuộc tính target của thành phần <form>
.
Thuộc tính formtarget
hoạt động với các kiểu input sau: submit và image.
Một biểu mẫu với hai nút gửi, với các cửa sổ target khác nhau:
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
<input type="submit" formtarget="_blank" value="Submit to a new window/tab">
</form>
<!DOCTYPE html>
<html>
<body>
<h1>The input formtarget attribute</h1>
<p>The formtarget attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form.</p>
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
<input type="submit" formtarget="_blank" value="Submit to a new window/tab">
</form>
</body>
</html>
Thuộc tính formnovalidate
chỉ định thành phần <input> không nên được xác thực khi được gửi.
Ghi chú: Thuộc tính này ghi đè thuộc tính novalidate của thành phần <form>
.
Thuộc tính formnovalidate
hoạt động với các kiểu input sau: submit.
Một biểu mẫu với hai nút gửi (cùng và không cùng với sự xác thực):
<form action="/action_page.php">
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Submit">
<input type="submit" formnovalidate="formnovalidate"
value="Submit without validation">
</form>
<!DOCTYPE html>
<html>
<body>
<h1>The input formnovalidate attribute</h1>
<form action="/action_page.php">
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email" required><br><br>
<input type="submit" value="Submit">
<input type="submit" formnovalidate="formnovalidate" value="Submit without validation">
</form>
<p><strong>Note:</strong> The formnovalidate attribute of the input tag is not supported in Safari 10 (or earlier).</p>
</body>
</html>
Thuộc tính novalidate
là một thuộc tính của <form>
.
Khi xuất hiện, novalidate chỉ định toàn bộ các dữ liệu biểu mẫu không nên được xác thực khi được gửi.
Xác định rằng không dữ liệu biểu mẫu nào nên được xác thực khi gửi:
<form action="/action_page.php" novalidate>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Submit">
</form>
<!DOCTYPE html>
<html>
<body>
<h1>The form novalidate attribute</h1>
<p>The novalidate attribute specifies that the form data should not be validated when submitted.</p>
<form action="/action_page.php" novalidate>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email" required><br><br>
<input type="submit" value="Submit">
</form>
<p><strong>Note:</strong> The novalidate attribute of the form tag is not supported in Safari 10 (or earlier).</p>
</body>
</html>
Ứng Dụng Học
Theo dõi cập nhật nội dung học trên Youtube & Facebook
Thông Tin Liên Hệ
Công Ty Cổ Phần Phát Triển Công Nghệ Gozic.
Website: https://gozic.vn
SĐT: 096 - 70 25 996
Email: ziczacgroup@gmail.com
Thiết kế webiste chuyên nghiệp
Thiết kế phần mềm quản trị
Thiết kế ứng dụng Android
Thiết kế ứng dụng IOS
Thiết kế Web App
Hỗ trợ Digital Marketing
Hỗ trợ quảng cáo Google Ads
Hỗ trợ quảng cáo Facebook Ads
Hỗ trợ SEO Website