Beruflich Dokumente
Kultur Dokumente
HTML Forms
1
Introduction
WEB
BROWSER SERVER
2
FORM Example
3
<FORM> …… </FORM> Tag
• METHOD:
¾Indicates how the information in the form
will be sent to the web server when the
form is submitted.
¾Two possible values:
POST: causes a form’s contents to be parsed
one element at a time.
GET: concatenates all field names and values
in a single large string.
¾POST is the preferred method because of
string size limitations in most systems.
4
• ACTION:
¾Specifies the URL of a program on the
origin server that will be receiving the
form’s inputs.
¾Traditionally called Common Gateway
Interface (CGI).
Details of CGI to be discussed later.
¾The specified program is executed on
the server, when the form is submitted.
Output sent back to the browser.
• Typical usage:
<FORM METHOD=“POST”
ACTION=“cgi-bin/myprog.pl”>
……..
……..
</FORM>
5
<INPUT> Tag
• TYPE:
¾Defines the kind of element that is to be
displayed in the form.
“TEXT” – defines a text box, which provides
a single line area for entering text.
“RADIO” – radio button, used when a choice
must be made among several alternatives
(clicking on one of the buttons turns off all
others in the same group).
“CHECKBOX” – similar to the radio buttons,
but each box here can be selected
independently of the others.
6
“PASSWORD” – similar to text box, but
characters are not shown as they are typed.
“HIDDEN” – used for output only; cannot be
modified (mainly used to refer to choices that
have already been made earlier).
“IMAGE” – used for active maps. When the user
clicks on the image, the (x,y) co-ordinates are
stored in variables, and are returned for further
processing.
“SUBMIT” – creates a box labeled Submit; if
clicked, the form data are passed on to the
designated CGI script.
“RESET” – creates a box labeled Reset; if
clicked, clears a form’s contents.
• NAME:
¾Specifies a name for the input field.
¾The input-handling program (CGI) in reality
receives a number of (name,value) pairs.
• SIZE:
¾Defines the number of characters that can
be displayed in a TEXT box without
scrolling.
• MAXLENGTH:
¾Defines the maximum number of
characters a TEXT box can contain.
7
• VALUE:
¾Used to submit a default value for a TEXT or
HIDDEN field.
¾Can also be used for specifying the label of
a button (renaming “Submit”, for example).
• SRC:
¾Provides a pointer to an image file.
¾Used for clickable maps.
• ALIGN:
¾Used for aligning image types.
¾ALIGN = TOP | MIDDLE | BOTTOM
8
<SELECT> …. </SELECT> Tag
9
Example 1
<HTML>
<HEAD>
<TITLE> Using HTML Forms </TITLE>
</HEAD>
10
Example 2
<HTML>
<HEAD>
<TITLE> Using HTML Forms </TITLE>
</HEAD>
11
<FORM METHOD="POST" ACTION="/cgi/feedback">
<P> Name: <INPUT NAME="name" TYPE="TEXT"
SIZE="30" MAXLENGTH="50">
<P> Roll Number:
<INPUT NAME="rollno" TYPE="TEXT" SIZE="7">
<P> Course Numbers:
<INPUT NAME="course1" TYPE="TEXT" SIZE="6">
<INPUT NAME="course2" TYPE="TEXT" SIZE="6">
<INPUT NAME="course3" TYPE="TEXT" SIZE="6">
<P> Category: SC <INPUT NAME="cat" TYPE=RADIO>
ST <INPUT NAME="cat" TYPE=RADIO>
GE <INPUT NAME="cat" TYPE=RADIO>
12
Example 3
<HTML>
<HEAD>
<TITLE> Using HTML Forms </TITLE>
</HEAD>
13
<FORM METHOD="POST" ACTION="/cgi/feedback">
<P> Name: <INPUT NAME="name" TYPE="TEXT"
SIZE="30" MAXLENGTH="50">
<P> Roll Number:
<INPUT NAME="rollno" TYPE="TEXT" SIZE="7">
<P> Password:
<INPUT NAME="code" TYPE=PASSWORD
SIZE="10">
<P> Course Numbers:
<INPUT NAME="course1" TYPE="TEXT" SIZE="6">
<INPUT NAME="course2" TYPE="TEXT" SIZE="6">
<INPUT NAME="course3" TYPE="TEXT" SIZE="6">
14
<P> Languages known:
English <INPUT NAME="lang" TYPE=CHECKBOX>
Hindi <INPUT NAME="lang" TYPE=CHECKBOX>
<P> Scholarship holder (select for yes):
<INPUT NAME="schol" TYPE=CHECKBOX>
<P> General feedback:
<TEXTAREA NAME="feed" ROWS=3 COLS=20>
</TEXTAREA>
<P> <P> Thanks for the information.
<P> <INPUT TYPE="SUBMIT" VALUE="DONE">
<INPUT TYPE="RESET" VALUE="CLEAR FORM">
</FORM>
</BODY>
</HTML>
15
How to Submit a Form?
original page
P P
submit form
cgi
new html page
Browser
16
• Web page including form
¾Resides on the web server in the regular
folder where html files and other
documents are kept.
• CGI script program handling form data
¾Resides under a special folder on the web
server (usually, “cgi-bin).
¾May be written in Perl, C, shell script, etc.
• Web page linked to the cgi script.
<FORM METHOD=“POST”
ACTION=“cgi-bin/myprog.pl”>
……..
……..
</FORM>
17
How to Write the CGI Program?
• Must know …
¾How to access the form data.
Mechanism depends on METHOD (GET or
POST).
¾How to return processed output back to
the browser.
HTML file created on the fly (typically).
• Details to be discussed later.
¾Good idea to have a look at a typical
Perl script.
18
SOLUTIONS TO QUIZ
QUESTIONS ON
LECTURE 16
19
Quiz Solutions on Lecture 16
20
Quiz Solutions on Lecture 16
21
QUIZ QUESTIONS ON
LECTURE 17
22
Quiz Questions on Lecture 17
23