Forms
- An HTML form is used to collect user input.
- The user input is sent to a server for processing and storage.
Form <form>
- Used to create an HTML form for user input
- Container for different types of input elements
<form>
<div>
<label for="name">Enter your name:</label>
<input type="text" name="name" id="name">
</div>
</form>
Attributes
action
- Defines the action to be performed when the form is submitted.
- Contains the URL that processes the form data.
<form action="checkout.asp">
</form>
method
- Specifies the HTTP method to be used when submitting the form data.
- Possible values are
get
andpost
get
- Appends the form data to the URL, in name/value pairs
- NEVER use
get
to send sensitive data. - The length of a URL is limited (2048 characters)
- Useful for form submissions where a user wants to bookmark the result
- Use this method when the form has no side-effects.
post
- Appends the form data inside the body of the HTTP request.
- POST has no size limitations, and can be used to send large amounts of data.
- Form submissions with POST cannot be bookmarked
- Always use POST if the form data contains sensitive or personal information.
<form action="checkout.asp" method="post">
</form>
enctype
- Specifies how the form-data should be encoded when submitting it to the server.
- Used only if
method="post"
. - Possible values
application/x-www-form-urlencoded
: Default. All characters are encoded before sentmultipart/form-data
: Used when the user uploads a filetext/plain
: Useful for debugging purposes.
<form action="checkout.asp" method="post" enctype="multipart/form-data">
<input type="file">
</form>
target
- Specifies where to display the response that is received after submitting the form.
- Possible values are
_blank
,_self
,_parent
,_top
,framename
autocomplete
Specifies whether a form should have autocomplete on or off.
<form action="/checkout.asp" autocomplete="on">
novalidate
- Specifies that the form-data (input) should not be validated when submitted.
- A boolean attribute.
<form action="checkout.asp">
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit">
</form>