X Unit II Chapter 9
X Unit II Chapter 9
9
HTML
FORMS
INTRODUCTION
Forms are an essential part of the Internet, as they provide
a way for web sites to capture information from users and
process requests. For many different reasons people or
companies are asking for our e‐mail addresses, names and
Objectives: site URLs. Buying products on the Internet today is quite
common and with the advent of security devices, the
Understanding HTML Web Forms
method used for submitting your details and hard earned
How HTML Forms work money is usually performed via forms.
Creating a Form using <form> Tag
In this lesson we'll discuss how to use HTML to mark up a
Using <input> Tag and its Attributes
form, what elements to use to capture different types of
Creating Selection list, Check Boxes, Radio Buttons, data. We won't get too deep into how information from a
Menus & Text Areas
form is processed and handled on the back end of a
Placing Image in the Form website as form processing is a deeper topic, for now we'll
Understanding Submit button stick to the creation of forms.
144
9.1 UNDERSTANDING HTML FORMS
An HTML form is a part of a web page that is required when you want to collect some Definition
data from the site visitor. For example registration information: name, email address, Forms provide a way for web sites to
credit card, etc. Generally web forms allow web page readers to send their feedbacks, capture information from users and to
process requests, also they offer
orders or other information to the host of web page. A form will take input from the site
controls for nearly every imaginable
visitor and then will post it to the web server. Then back‐end application will do the use of an application.
required processing on that data in whatever way the companies require.
HTML forms are a composition of buttons, check boxes and text input
fields embedded inside the HTML documents with one goal in mind
i.e. to capture user input. By doing things such as providing fields for Label
user data such as names, phone number and email addresses, web
forms give users the opportunity to interact directly with a web page.
Option Buttons
HOW HTML FORM WORKS?
Text input fields
Before making the HTML form, one should know how the information
filled by the reader in a form makes its way back to the publisher. Web Check boxes
publisher needs to have a person who runs the web server computer
and sets it to process his forms. Almost all ISP companies offering web
page hosting also provide pre‐programmed scripts to their customers
for processing forms. Buttons
2 Form Submission 3
1 Webserver
Form processor
4 script
Visitor's se
web 5 Respon
browser
1 Visitor loads the form: The browser sends a request to the web server. The web server returns the HTML page that
contains the form.
2 Visitor fills the form and submits it: Every form must include a button for the user to submit the form. When someone
clicks that button, all the information visitor has filled in is sent (in a standard format) to an Internet address that you
specify in the form itself.
The form submission data is sent to the web server: Once the visitor has submitted the form, the form data is sent to
3
the web server. In the form, the author of the form has to mention an 'action' URL that tells the browser where to send
the form submission data. The 'action' usually points to the URL of a script that knows what to do with the data.
4 The web server processes the request: The web server passes the form submission data to the form processor script
(mentioned by the 'action'). The form processor script is written in languages like PHP, ASP, or Perl. The form processor
script can send the form data by email or save the data to a database file.
5 A response is sent back to the browser: The form processor script sends a response indicating the success or failure of
the form processing operations back to the server. The response could be re‐directed to another web page.
Method: Tells the browser how to send form data to a web Action: The action attribute contains path information so
server. The method attribute is always 'post', which means that the server knows what script or program it (the
to send the form entry result as a document. If you use the server) has to execute.
'GET' method, the results of your form will appear in the
URL box in the top of the browser and name value pairs,
separated by '&'.
Example: Modify the above example with <label> tag and save the file as webform.htm.
<html>
<head><title>FORM</title></head>
</body>
<body bgcolor="pink">
<font face= “arial”>
<h1 align=“center”> ENTRY FORM </h1>
<img src="picture.jpg" width="200" height="200"
align="right" >
<form>
<label for="pass">ENTER PASSWORD:<input
type=“password” name=”pass” size=”10”></label>
<p><label for="name">ENTER NAME:<input type=
“text” name= “name” value="enter your name here"
size= “20” maxlength= “30” /></label>
<p><label for="age">ENTER AGE:<input type=“text” name= “age” size=“2” maxlength=“3”
/></label>
<p><label for="add">ENTER ADDRESS:<input type=“text” name= “add” size=“30”
maxlength= “40” /></label>
<p><label for="email">ENTER E-MAIL:<input type=“text” name= “email” size=“15”
maxlength= “20” /></label>
<p><label for="telno">ENTER TELEPHONE NO:<input type=“text” name= “telno” size=“8”
maxlength=”10” /></label>
</form>
</body>
</html>
<p> GENDER
<input type= “radio” name=”gender”
checked= "checked”/>MALE
<input type= “radio” name=”gender” />FEMALE
9.5 MENUS
Menus are used to allow the user to select one or more from a list of options. Pull‐down menus and scrollable menus are
both created with the <select>. . </select> and <option>. . </option> tags. The <select> tag has one required attribute, NAME
and two optional attributes, SIZE and MULTIPLE.
<html>
<head><title>FORM</title></head>
<form method="post">
<body bgcolor="silver">
<font face="arial">
<h1 align="center"><font color="red">
REGISTRATION FORM</font></h1>
<fieldset>
<p>ENTER YOUR NAME <input type= “text” size= “20” maxlength= “30” />
<p>ENTER YOUR AGE<input type= “text” size“2” maxlength= “3” />
<P>ENTER YOUR ADDRESS <input type=“text” size= “30” maxlength= “40” />
<p>ENTER YOUR E-MAIL ID <input type=“text” size= “15” maxlength= “20” />
</fieldset>
<input type="image" src="submit1.jpg" width="70" height="70" />
<input type="image" src="reset1.jpg" width="70" height="70" />
</form>
</body>
</html>
RECAP BYTE
Html forms provide an area where visitor can enter information to be sent back to the server of the web page.
<form> tag defines a form within html document.
Multiple <form> elements are allowed in a single page, but nested <form> elements are not allowed.
<form> tag has two attributes i.e. method and action.
Method attribute is always ‘post’ means to send the form information as a document or data.
Action attribute specifies the Internet address to which form data is sent.
<input> tag is used to ask the visitor to put information within form.
Type attribute with <input> tag specifies the data type for the variables used to input the data.
Size attribute with <input> tag indicates the size of text input box.
Maxlength attribute with <input> tag specifies the number of characters the user is allowed to enter into the text box.
Check boxes appear as a small square and allow the user to input the data by clicking them.
Radio buttons are used when either of the choice has to be selected.
<select> tag creates selection lists where the option for choices are displayed either as scrolling list or pull‐down pick list.
<option> tag is used together with <select> tag.
<textarea> tag creates text areas that allow the user to enter multiple lines of text in a single input box.
Rows and cols attribute of the <textarea> tag controls the number of rows and columns of text area.
Submit button is used to submit the form data to the server.
Reset button clears all the current entries in the form so that you can start entering new data from the beginning.
i) A part of a web page used to collect some data from viii) An attribute with <input> tag that specifies the kind of
the site visitor and sent it to the host of the web site. data to be entered in a particular field.
a) Comment Page b) Feed back Page a) data b) declare
c) Form d) Submit form c) type d) none of them
ii) Following are parts of the web forms, except one. ix) The attribute with <input> tag that indicates how
a) Input text fields b) Buttons many characters wide the text input box should be.
c) Images d) Tools a) <length> b) <size>
iii) The tag which implements the form's interface. c) <numbers> d) <width>
a) <start form> b) <open form> x) An object on the form page which submits the form
c) <form> d) <start form> data to the web server.
iv) A <form> tag has these two required attributes. a) go button b) save button
a) Start and Stop b) Get and Post c) submit button d) reset button
c) Method and Action d) Begin and End xi) A <form> tag attribute that is used to send the form
entry result as a document.
v) The following tags are used within <form> tag, except
one: a) method b) send
a) <input> b) <option> c) submit d) post
c) <select> d) <color> xii) An attribute of the <form> tag that specifies the URL
to which the data is sent.
vi) The tag used to ask the visitor to enter information
within a form. a) address b) url
a) <input> b) <info> c) action d) method
c) <enter> d) <mail to>
vii) The type of control used when only one option is to ANSWERS i) a ii) d iii) c iv) c v) d vi) a
be selected from the set of alternatives. vii) b viii) c ix) b x) c xi) d xii ) c
a) Check boxes b) Radio buttons
2. State whether the following statements are True or False by ticking (3) them accordingly. True False
a) <form> tag can be nested within <form> tag.
b) <form> tag can be placed anywhere in the html document.
c) In forms, image can't be used in a submit button.
d) Size attribute is valid for the submit button.
e) Check boxes are used where multiple selection of information is required.
f) Radio buttons are the best option to choose the gender of the visitor.
ANSWERS a) T b) T c) F d) F e) T f) T
ANSWERS a) <form> tag b) <input> tag c) <textarea> tag d) Radio buttons e) Menus f) Submit button