0% found this document useful (0 votes)
23 views20 pages

HTML Forms

The document provides an introduction to HTML forms, detailing their purpose in collecting user data through various controls such as text inputs, checkboxes, radio buttons, and select boxes. It explains how to create forms using the <form> tag and outlines common attributes and controls, including examples for each type. Additionally, it discusses the importance of grouping related controls for user-friendliness using the <fieldset> and <legend> elements.

Uploaded by

nalumansitheresa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views20 pages

HTML Forms

The document provides an introduction to HTML forms, detailing their purpose in collecting user data through various controls such as text inputs, checkboxes, radio buttons, and select boxes. It explains how to create forms using the <form> tag and outlines common attributes and controls, including examples for each type. Additionally, it discusses the importance of grouping related controls for user-friendliness using the <fieldset> and <legend> elements.

Uploaded by

nalumansitheresa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

INTRODUCTION TO WEB DESIGN

DCIS1204
SEMISTER TWO
YEAR ONE
HTML Forms

HTML Forms are required to collect different kind of data from the users inputs, such as contact
details like name, email address, phone numbers, or details like credit card information, etc.
Forms contain special elements called controls like inputbox, checkboxes, radio-buttons, submit
buttons, etc. Users generally complete a form by modifying its controls e.g. entering text, selecting
items, etc. and submitting this form to a web server for further processing.
The <form> tag is used to create an HTML form.
<form action = "Script URL" method = "GET|POST">
form elements like input, textarea etc.
</form>
HTML Forms

Form Attributes
Apart from common attributes, following is a list of the most frequently used form attributes
HTML Forms

HTML Form Controls


Text Input Controls
Checkboxes Controls
Radio Box Controls
Select Box Controls
File Select boxes
Hidden Controls
Clickable Buttons
Submit and Reset Button
HTML Forms

HTML Form ControlsText Input Controls


There are three types of text input used on forms
Single-line text input controls − 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.
Password input controls − This is also a single-line text input but it masks the character as soon
as a user enters it. They are also created using HTMl <input> tag.
Multi-line text input controls − This is used when the user is required to give details that may
be longer than a single sentence. Multi-line input controls are created using HTML <textarea> tag.
HTML Forms

Example of Single-line text input controls


<!DOCTYPE html>
<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form >
<label> First name:</label> <input type = "text" name = "first_name"/>
<br>
<label>Last name:</label> <input type = "text" name = "last_name" />
</form>
</body>
</html>
HTML Forms

Attributes for <input> tag for creating text field


HTML Forms

Password input controls


This is also a single-line text input but it masks the character as soon as a user enters it. They are also created using HTML <input>tag but
type attribute is set to password.
Example 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>
</html>
HTML Forms

Multiple-Line Text Input Controls


This is used when the user is required to give details that may be longer than a single sentence. Multi-line input controls are created using
HTML <textarea> tag.
<!DOCTYPE html>
<html>
<head>
<title>Multiple-Line Input Control</title>
</head>
<body>
<form>
Description : <br />
<textarea rows = "5" cols = "50" name = "description">
Enter description here...
</textarea>
</form>
</body>
</html>
HTML Forms
HTML Forms

Checkbox form Control


Checkboxes are used when more than one option is required to be selected. They are also created using HTML <input> tag but type attribute is set to
checkbox..
Example
<!DOCTYPE html>
<html>
<head>
<title>Checkbox Control</title>
</head>
<body>
<form>
<input type = "checkbox" name = "maths" value = "on" checked> Maths
<input type = "checkbox" name = "physics" value = "on"> Physics
<input type = "checkbox" name = "physics" value = "on"> Biology
<input type = "checkbox" name = "physics" value = "on"> Chemistry
</form>
</body>
</html>
HTML Forms
HTML Forms

Radio Button Control


Radio buttons are used when out of many options, just one option is required to be selected. They are also created using HTML <input> tag but type
attribute is set to radio.
Example
<!DOCTYPE html>
<html>
<head>
<title>Radio Box Control</title>
</head>
<body>
<form>
<input type = "radio" name = "subject" > male
<input type = "radio" name = "subject" > female
</form>
</body>
</html>
HTML Forms

Select Box Control


A select box, also called drop down box which provides option to list down various options in the form of drop down list, from where a user can select
one or more options.
Example
<!DOCTYPE html>
<html>
<head>
<title>Select Box Control</title>
</head>
<body>
<form>
<select name = "dropdown">
<option value = "English" selected>English</option>
<option value = "SST">SST</option>
</select>
</form>
</body>
</html>
HTML Forms
HTML Forms
HTML Forms

Button Controls
There are various ways in HTML to create clickable buttons. You can also create a clickable button
using <input>tag by setting its type attribute to button. The type attribute can take the following
values.
HTML Forms

<!DOCTYPE html>
<html>
<head>
<title>File Upload Box</title>
</head>
<body>
<form>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
<input type = "button" name = "ok" value = "OK" />
<input type = "image" name = "imagebutton" src = "/html/images/logo.png" />
</form>
</body>
</html>
HTML Forms

Hidden Form Controls: Hidden form controls are used to hide data inside the page which later on can be pushed to the server. This control hides inside
the code and does not appear on the actual page. For example, following hidden form is being used to keep current page number. When a user will click
next page then the value of hidden control will be sent to the web server and there it will decide which page will be displayed next based on the passed
current page.
Example
<!DOCTYPE html>
<html>
<head>
<title>File Upload Box</title>
</head>
<body>
<form>
<p>This is page 10</p>
<input type = "hidden" name = "pagename" value = "10" />
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</form>
</body>
</html>
HTML Forms

Grouping Form Controls


You also group logically related controls and labels within a web form using the <legend> element.
Grouping form controls into categories makes it easier for users to locate a control which makes the
form more user-friendly. Let's try out the following example to see how it works:
<form>
<fieldset>
<legend>Contact Details</legend>
<label>Email Address: <input type="email" name="email"></label>
<label>Phone Number: <input type="text" name="phone"></label>
</fieldset>
</form>

You might also like