HTML Chapter 4 Forms
HTML Chapter 4 Forms
The HTML <form> tag is used to create an HTML form and it has following
syntax:
This control is used for items that require only one line
of user input, such as search boxes or names. They are
created using HTML <input> tag.
TEXT INPUT CONTROLS EXAMPLE
<!DOCTYPE html>
<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form >
First name: <input type = "text" name = "first_name" />
<br>
Last name: <input type = "text" name = "last_name" />
</form>
</body>
Link
</html>
TEXT INPUT CONTROLS ATTRIBUTES
Sr.No Attribute & Description
1 type
Indicates the type of input control and for text input control it will be
set to text.
2 name
Used to give a name to the control which is sent to the server to be
recognized and get the value.
3 value
This can be used to provide an initial value inside the control.
4 size
Allows to specify the width of the text-input control in terms of
characters.
5 maxlength
Allows to specify the maximum number of characters a user can
enter into the text box.
PASSWORD INPUT CONTROLS
2- Password input controls
<!DOCTYPE html>
<html>
<head>
<title>Password Input Control</title>
</head>
<body>
<form >
User ID : <input type = "text" name = "user_id" />
<br>
Password: <input type = "password" name = "password" />
</form>
</body>
Link
</html>
PASSWORD INPUT CONTROLS
Sr.No Attribute & Description
1 type
Indicates the type of input control and for password input control it
will be set to password.
2 name
Used to give a name to the control which is sent to the server to be
recognized and get the value.
3 value
This can be used to provide an initial value inside the control.
4 size
Allows to specify the width of the text-input control in terms of
characters.
5 maxlength
Allows to specify the maximum number of characters a user can
enter into the text box.
Password Field:-
3- MULTIPLE-LINE TEXT INPUT CONTROLS
Text Area Field:-
Text Area is similar to text box but it may consist of
multiple rows. It is used to get lengthy input from the user
like comments and suggestions etc.<TEXTAREA>tag is
used for it. Spell Check is default value is true.
Example:-
<html>
<head>
<title>Checkbox Control</title>
</head>
<body>
<form>
<input type="checkbox" name="maths" value="on"> Maths
<input type="checkbox" name="physics" value="on“checked>
Physics
</form>
</body>
</html> Link
Radio Button:-
Radio Buttons are used when user has to choose
one option from multiple choices.
Attributes:-
➢ Name: It specifies the name of radio button.
Link
Note: Name must be same
Exercise No.3
Link
Select Field:-
Select field is used to provide predefined list of items to
the user the user can choose one or multiple option from the
list.
Attribute:-
<html>
<body>
Choose Your City:
<select name="City">
<option value="Islamabad" selected>Islamabad
<option value="Lahore">Lahore
<option value="Faisalabad">Faisalabad
<option value="Quetta">Quetta
</select>
</body>
<html>
Link
Example of Selected Field:-
<!DOCTYPE html>
<html>
<body>
<select>
<option value="UAF">UAF</option>
<option value="NTU">NTU</option>
<option value="MIU">MIU</option>
<option value="GCUF" selected>GCUF</option>
</select>
</body>
</html>
Link
BUTTON CONTROLS
Example:-
<INPUT TYPE=“submit”>
Reset Button:-
Reset Button is predefined button. It is used to
reset the form.<BUTTON> tag is used for it.
Example:-
<INPUT TYPE=“reset”>
Link
Button:-
Button is used in forms to process the form
data. <BUTTON> tag is used to create a button in
the form.
Attribute:-
Example:-
<h3> Using button in the form</h3>
<Form name="form1">
<input type="button" value="Click Here for HTML" >
<input type="button" value="Click Here for CSS" > Text
</Form>
File Upload Field:-
File upload field is used to get files from the user in a
form. The visitors can select a file from the disk using
this field. <FILE> tag is used to create file upload
field.
Example:-
Link
HTML <INPUT> PLACEHOLDER ATTRIBUTE
The placeholder attribute specifies a short hint that
describes the expected value of an input field (e.g. a
sample value or a short description of the expected
format).
The short hint is displayed in the input field before the
user enters a value.
Note: The placeholder attribute works with the
following input types: text, search, url, tel, email, and
password.
Link
HTML <BUTTON> FORM ATTRIBUTE
The form attribute specifies one or more forms the
button belongs to.
Link
HTML TYPE=“IMAGE”
The form attribute specifies one or more forms the
button belongs to.
Link
THE MIN AND MAX ATTRIBUTES
The min and max attributes specify the minimum and
maximum values for an <input> element.
The min and max attributes work with the following
input types: number, range, date, datetime-local,
month, time and week.
The step Attribute
The step attribute specifies the legal number intervals
for an <input> element.
Example: if step="3", legal numbers could be -3, 0, 3, 6,
etc.
Link
THE REQUIRED ATTRIBUTE
The required attribute specifies that an input field
must be filled out before submitting the form.
The required attribute works with the following input
types: text, search, url, tel, email, password, date
pickers, number, checkbox, radio, and file.
Link
THE MULTIPLE ATTRIBUTE
The multiple attribute specifies that the user is
allowed to enter more than one value in the <input>
element.
The multiple attribute works with the following input
types: email, and file.
Link
THE PATTERN ATTRIBUTE
The pattern attribute specifies a regular expression
that the <input> element's value is checked against.
The pattern attribute works with the following input
types: text, search, url, tel, email, and password.
Tip: Use the global title attribute to describe the
pattern to help the user.
Link
PASSWORD PATTERN
Pattern=".{8,}"
PASSWORD PATTERN
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}"
EMAIL PATTERN
Pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"
URL PATTERN
https://www.w3schools.com/tags/att_input_pattern.asp
REFERENCE SITE
https://webdesign.tutsplus.com/tutorials/html5-form-
validation-with-the-pattern-attribute--cms-25145
REFERENCE SITE
http://html5pattern.com/Names
THE FORMTARGET ATTRIBUTE
The formtarget attribute specifies a name or a
keyword that indicates where to display the response
that is received after submitting the form.
The formtarget attribute overrides the target attribute
of the <form> element.
The formtarget attribute can be used with
type="submit" and type="image".
Link
THE FORMNOVALIDATE ATTRIBUTE
The formnovalidate attribute overrides the
novalidate attribute of the <form> element.
The formnovalidate attribute can be used with
type="submit".
Link
INPUT TYPE BUTTON ALERT
<input type="button"> defines a button:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Link