WINSEM2024-25 BCSE203E ELA VL2024250504384 2025-01-02 Reference-Material-I
WINSEM2024-25 BCSE203E ELA VL2024250504384 2025-01-02 Reference-Material-I
1. HTML Forms
2. HTML Form Attributes
3. HTML Form Label
4. HTML For fieldset
5. HTML Form Button
6. HTML Form Input
7. HTML Form Input Type
8. HTML Form Select
9. HTML Form textarea
10. HTML Form output
11. HTML Form Validation
1. HTML Forms
• Forms are the HTML mechanism for gathering input from the user.
• To create a basic form, you need three elements: the form, input, and button elements.
<html>
<body>
<form>
<input name="name" />
<button>Submit</button>
</form>
</body>
</html>
2. HTML Forms Attributes
HTML Forms : Method
The allowed values are get and post, which correspond to the HTTP GET
and POST methods.
The following code, set the post value for the form.
History Parameters remain in browser history Parameters are not saved in browser history
Restrictions on data Yes, when sending data, the GET method adds the No restrictions
length data to the URL; and the length of a URL is limited
(maximum URL length is 2048 characters)
Restrictions on data Only ASCII characters allowed No restrictions. Binary data is also allowed
type
Security GET is less secure compared to POST because data POST is a little safer than GET because the parameters are not
sent is part of the URL stored in browser history or in web server logs
Never use GET when sending passwords or other
sensitive information!
Visibility Data is visible to everyone in the URL Data is not displayed in the URL
Additional Methods:
• The PUT Method
• PUT is used to send data to a server to create/update a resource.
• The difference between POST and PUT is that PUT requests are idempotent.
• Calling the same PUT request multiple times will always produce the same result.
• In contrast, calling a POST request repeatedly have side effects of creating the
same resource multiple times.
► multipart/form-data
► This encoding is used to upload files to the server
► text/plain
► This encoding varies between browsers
HTML Forms : Enctype
application/x-www-form-urlencoded encoding
• The name and value of each data item is encoded using the same scheme that is used to encode
URLs.
• Special characters are replaced with their HTML entity counterpart.
• The name of the data item and the value are separated by the equals sign (=) and data/value
tuples are separated by the ampersand character(&).
multipart/form-data
• The multipart/form-data encoding tends to be used only for uploading files.
text/plain
• The mainstream browsers encode data in different ways for this encoding.
• Google Chrome encodes data in the same way as for the application/x-www-form-urlencoded
scheme, whereas Firefox encodes the data as follows:
fave=xml
name=example.com
Each data item is placed on a line, and special characters are not encoded.
HTML Forms : accept-charset
Value Description
_blank The response is displayed in a new window or tab
_self The response is displayed in the same frame (this is default)
_parent The response is displayed in the parent frame
_top The response is displayed in the full body of the window
framename The response is displayed in a named iframe
HTML Forms : autocomplete
on Default. The browser will automatically complete values based on values that the user has
entered before
off The user must enter a value into each field for every use. The browser does not
automatically complete entries
Attributes: for, form
</p>
Example 1
<form method="post" action="http://example.com/form">/></label>
<fieldset> </p>
<p>
<fieldset>
<legend>Enter Your Details</legend>
<p>
<label for="name">Name: <input id="name" name="name" /></label>
</p>
<p>
<label for="name">City: <input id="city" name="city" /></label>
</p>
</fieldset>
<fieldset>
<legend>Vote For Your Three Favorite Fruits</legend>
<p>
<label for="favel">#l: <input id="favel" name="favel" /></label>
</p>
<p>
<label for="fave2">#2: <input id="fave2" name="fave2" /></label>
</p>
<p>
<label for="fave3">#3: <input id="fave3" name="fave3" /></label>
</p>
</fieldset>
Example 1 Example 2
5. HTML Form Button
• There are three ways you can use button by setting the three
different type attribute.
• submit - Specifies that the button will be used to submit a form
• reset - Specifies that the button will be used to reset a form
• button - Specifies that the button has no specific semantic significance
associated.
formaction - Overrides the action attribute on the form element, and
Syntax
Syntax
<button type="submit">Submit</button>
<button type="button"><img src="http://www.example.com/style/download.png" alt="submit"
/></button>