Web Development & Design
Foundations with XHTML
Chapter 9
Key Concepts
2
Learning
Outcomes
 In this chapter, you will learn how to:
 Describe common uses of forms on web pages
 Create forms on web pages using the <form>,
<input />, <textarea>, and <select> tags
 Create forms that provide additional accessibility
features using the accesskey and tabindex attributes
 Associate form elements and element groups using the
<label>, <fieldset>, and <legend> tags
 Create custom image buttons and use the <button> tag
to include more variety and richer content than the
standard form button
 Describe the features of CGI
 Invoke server-side processing to handle form data
 Find free CGI resources on the Web
3
Overview
of Forms
 Forms are used all over the Web to
 Accept information
 Provide interactivity
 Types of forms:
 Search form, Order form, Newsletter sign-up
form, Survey form, Add to Cart form, and so
on…
4
Overview
of Forms
Form
 An XHTML element that contains and
organizes other Web document objects
such as
text boxes,
check boxes,
and buttons
that can accept information from web
site visitors.
5
Two Components
of Using Forms
1. The XHTML form
-- the web page user interface
and
2. The server-side processing
CGI - Common Gateway
Interface
CGI works with the form data and
sends e-mail, writes to a text file,
updates a database, or performs
some other type of processing on the
server.
6
XHTML
Using Forms
 <form> tag
 Contains the form elements on a web page
 Container tag
 <input /> tag
 Configures a variety of form elements including text boxes,
radio buttons, check boxes, and buttons
 Stand alone tag
 <textarea> tag
 Configures a scrolling text box
 Container tag
 <select> tag
 Configures a select box (drop down list)
 Container tag
 <option> tag
 Configures an option in the select box
 Container tag
7
<form>
Email: <input type="text" name="CustEmail" id="CustEmail"
/><br />
<input type="submit" />
</form>
Sample Form
XHTML
8
XHTML
<form> element
 The form tag attributes:
 action
 Specifies the server-side program or script that will
process your form data
 method
 get – default value, form data passed in URL
 post – more secure,
form data passed in HTTP Entity Body
 name
 Identifies the form
 id
 Identifies the form
9
XHTML<input /> Element
Text box
 Accepts text information
 Attributes:
 type=“text”
 name
 id
 size
 maxlength
 value
10
XHTML<input /> Element
Password box
 Accepts text information that needs
to be hidden as it is entered
 Attributes:
 type=“password”
 name
 id
 size
 maxlength
 value
11
XHTML<input /> Element
Check box
 Allows the user to select one or more
of a group of predetermined items
 Attributes:
 type=“checkbox”
 name
 id
 checked
 value
12
XHTML<input /> Element
Radio Button
 Allows the user to select exactly one from a
group of predetermined items
 Each radio button in a group is given the
same name and a unique value
 Attributes:
 type=“radio”
 name
 id
 checked
 value
13
XHTML<textarea> Element
Scrolling Text Box
 Configures a scrolling text box
 Attributes:
 name
 id
 cols
 rows
14
XHTML<select> Element
Select List
 Configures a select list (along with <option> tags)
 Also known as: Select Box, Drop-Down List,
Drop-Down Box, and Option Box.
 Allows the user to select one or more items
from a list of predetermined choices.
 Attributes:
 name
 id
 size
 multiple
15
XHTML<option> Element
Options in a Select List
 Configures the options in a Select List
 Attributes:
 value
 selected
16
XHTML<input /> Element
Submit Button
 Submits the form information
 When clicked:
 Triggers the action method on the <form> tag
 Sends the form data (the name=value pair for
each form element) to the web server.
 Attributes:
 type=“submit”
 name
 id
 value
17
XHTML<input /> Element
Reset Button
 Resets the form fields to their initial
values
 Attributes:
 type=“reset”
 name
 id
 value
18
XHTML<input /> Element
Button
 Offers a flexible user interface
 There is no default action when the button
is clicked
 Usually a JavaScript function is invoked
when a button is clicked
 Attributes:
 type=“button”
 name
 id
 value
19
XHTML<input /> Element
Hidden form data
 This form element is not displayed on the
web page.
 Hidden form fields
 Can be accessed by both client-side and
server-side scripting
 Sometimes used to contain information
needed as the visitor moves from page to
page.
 Attributes:
 type=“hidden”
 name
 id
 value
Hands-On Practice 9.2
Checkpoint 9.1
1. You are designing a web site for a client who
sells items in a retail store.
They want to create a customer list for e-mail
marketing purposes. Your client sells to
consumers and needs a form that accepts their
customer’s name and e-mail address.
Would you recommend using two input boxes
(one for the name and one for the e-mail) or
three input boxes (for the first name, last name,
and email address)?
Explain your answer.
21
Checkpoint 9.1
2. You are designing a survey form for a client. One
of the questions has 10 possible responses.
Only one response can be selected per question.
What type of form element would you use to
configure this question on the web page?
3. True or False.
In a radio button group, the value attribute is used
by the browser to process separate elements as a
group.
22
23
<form>
<table border="0" width="75%">
<tr>
<td align="right" width="10%">Name: </td>
<td>
<input type="text" name= "CustName"
id= "CustName " size="30" /></td>
</tr>
<tr>
<td align="right" width="10%">Email: </td>
<td>
<input type="text" name="CustEmail"
id="CustEmail" /></td>
</tr>
<tr>
<td align="right" width="10%">
<input type="submit" value="Submit" /></td>
<td><input type="reset" /></td>
</tr>
</table>
</form>
XHTML
Using a
Table to
Format
a Form
24
XHTML Form Enhancements
<label> Element
 Associates a text label with a form
element
 Two Different Formats:
<label>Email: <input type="text"
name="CustEmail" id ="CustEmail" /></label>
Or
<label for="email " >Email: </label><input
type="text" name="CustEmail" id= "email " />
25
XHTML Form Enhancements
<fieldset> & <legend> elements
 The Fieldset Element
 Container tag
 Creates a visual group of form elements on a web page
 The Legend Element
 Container tag
 Creates a text label within the fieldset
<fieldset><legend>Customer Information</legend>
<label>Name:
<input type="text" name="CustName"
id="CustName" size="30" /></label><br />
<label>Email:
<input type="text" name="CustEmail"
id="CustEmail" /></label>
</fieldset>
26
XHTML Form Enhancements
tabindex attribute
 Attribute that can be used on form
elements and anchor tags
 Not supported by all browsers
 Modifies the default tab order
 Assign a numeric value
<input type="text" name="CustEmail"
id="CustEmail" tabindex="1" />
27
XHTML Form Enhancements
accesskey attribute
 Attribute that can be used on form
elements and anchor tags
 Not supported by all browsers
 Create a “hot-key” combination to place
the focus on the component
 Assign a value of a keyboard letter
 On Windows use the CTRL and the “hot-
key” to move the cursor
<input type="text" name="CustEmail"
id="CustEmail" accesskey="E" />
28
XHTML Form Enhancements
<input /> Element Image Button
 Submits the form
 When clicked:
 Triggers the action method on the <form> tag
 Sends the form data (the name=value pair for
each form element) to the web server.
 Attributes:
 type=“image”
 name
 id
 src
29
XHTML Form Enhancements
<button> Element
 A container tag
 When clicked, its function depends on the
value of the type attribute.
 Can contain a combination of text, images,
and media
 Attributes:
 type=“submit”, type=“reset”, type=“button”
 name
 id
 alt
 value
30
Checkpoint 9.2
1. Describe the purpose of the fieldset and legend
tags.
2. Describe the purpose of the accesskey attribute
and how it supports accessibility.
3. When designing a form, should you use the
standard submit button, an image button or a
button tag?
Are these different in the way that they provide for
accessibility?
Explain your answer.
31
Using CSS
to Style a Form
 Moderate Approach
 Use a table to format the form but
configure styles instead of XHTML table
attributes.
table { border: 3px solid #000000;
width: 100%;}
td { padding: 5px;
margin: 0px;}
.mylabel { text-align: right;}
32
Using CSS to
Style a Form
“Pure" CSS Approach
 Do not use a table to
format the form.
 Use CSS divs and spans
with positioning properties to
configure the page.
#myForm {border:3px solid #000000;
padding:10px;margin:10px;}
.myRow {height:30px;}
.myRowComments {margin-bottom:20px;}
33
Server-Side
Processing
 Your web browser requests web pages
and their related files from a web server.
 The web server locates the files and
sends them to your web browser.
 The web browser then renders the
returned files and displays the requested
web pages for you to use.
34
CGI
Common Gateway Interface
 A protocol for a web server to pass a web
page user's request to an application
program and accept information to send to
the user.
35
Steps in Utilizing CGI
1. Web page invokes CGI by a form
action or hyperlink, etc...
 Any form information is sent in the form of
name=value pairs to the web server.
2. Script on web server is executed
3. Script accesses requested database,
file, or process
4. Web server returns web page with
requested information or confirmation
of action
36
Common Uses of
Server-Side Scripting &
CGI
 Search a database
 Place an order at an online store
 Send a web page to a friend
 Subscribe to a newsletter
 Any type of server-side file or e-mail
processing is a candidate for CGI
37
Checkpoint 9.3
1. Describe CGI.
2. Code the form tag for a web page
form that will use the post method
to invoke a server-side script
located at
http://webdevfoundations.net/scripts/formdemo.asp
38
Sources of Free
Server-Side Processing
 Many web host providers offer free scripts for their
clients. Contact their support area or FAQ to learn
more about their services.
 Some web sites that offer FREE remotely hosted
scripts (in return for displaying an ad).
 http://formbuddy.com
 http://hostedscripts.com
 http://response-o-matic.com
 http://master.com
 http://www.formmail.com
 http://wufoo.com
 http://iceberg.com
 http://formassembly.com
39
Languages that
support CGI
 Programs or scripts that work with CGI
can be written in many languages:
 PHP
 Perl
 C
 C++
 Active Server Pages (ASP)
 Java Server Pages (JSP)
 ASP.NET
 Ruby on Rails
 And so on….
40
Summary
 This chapter introduced the use of
forms on web pages.
 You learned about how to configure
form elements and provide for
accessibility.
 You also learned about CGI and how to
configure a form to access server-side
processing.

Chapter09

  • 1.
    Web Development &Design Foundations with XHTML Chapter 9 Key Concepts
  • 2.
    2 Learning Outcomes  In thischapter, you will learn how to:  Describe common uses of forms on web pages  Create forms on web pages using the <form>, <input />, <textarea>, and <select> tags  Create forms that provide additional accessibility features using the accesskey and tabindex attributes  Associate form elements and element groups using the <label>, <fieldset>, and <legend> tags  Create custom image buttons and use the <button> tag to include more variety and richer content than the standard form button  Describe the features of CGI  Invoke server-side processing to handle form data  Find free CGI resources on the Web
  • 3.
    3 Overview of Forms  Formsare used all over the Web to  Accept information  Provide interactivity  Types of forms:  Search form, Order form, Newsletter sign-up form, Survey form, Add to Cart form, and so on…
  • 4.
    4 Overview of Forms Form  AnXHTML element that contains and organizes other Web document objects such as text boxes, check boxes, and buttons that can accept information from web site visitors.
  • 5.
    5 Two Components of UsingForms 1. The XHTML form -- the web page user interface and 2. The server-side processing CGI - Common Gateway Interface CGI works with the form data and sends e-mail, writes to a text file, updates a database, or performs some other type of processing on the server.
  • 6.
    6 XHTML Using Forms  <form>tag  Contains the form elements on a web page  Container tag  <input /> tag  Configures a variety of form elements including text boxes, radio buttons, check boxes, and buttons  Stand alone tag  <textarea> tag  Configures a scrolling text box  Container tag  <select> tag  Configures a select box (drop down list)  Container tag  <option> tag  Configures an option in the select box  Container tag
  • 7.
    7 <form> Email: <input type="text"name="CustEmail" id="CustEmail" /><br /> <input type="submit" /> </form> Sample Form XHTML
  • 8.
    8 XHTML <form> element  Theform tag attributes:  action  Specifies the server-side program or script that will process your form data  method  get – default value, form data passed in URL  post – more secure, form data passed in HTTP Entity Body  name  Identifies the form  id  Identifies the form
  • 9.
    9 XHTML<input /> Element Textbox  Accepts text information  Attributes:  type=“text”  name  id  size  maxlength  value
  • 10.
    10 XHTML<input /> Element Passwordbox  Accepts text information that needs to be hidden as it is entered  Attributes:  type=“password”  name  id  size  maxlength  value
  • 11.
    11 XHTML<input /> Element Checkbox  Allows the user to select one or more of a group of predetermined items  Attributes:  type=“checkbox”  name  id  checked  value
  • 12.
    12 XHTML<input /> Element RadioButton  Allows the user to select exactly one from a group of predetermined items  Each radio button in a group is given the same name and a unique value  Attributes:  type=“radio”  name  id  checked  value
  • 13.
    13 XHTML<textarea> Element Scrolling TextBox  Configures a scrolling text box  Attributes:  name  id  cols  rows
  • 14.
    14 XHTML<select> Element Select List Configures a select list (along with <option> tags)  Also known as: Select Box, Drop-Down List, Drop-Down Box, and Option Box.  Allows the user to select one or more items from a list of predetermined choices.  Attributes:  name  id  size  multiple
  • 15.
    15 XHTML<option> Element Options ina Select List  Configures the options in a Select List  Attributes:  value  selected
  • 16.
    16 XHTML<input /> Element SubmitButton  Submits the form information  When clicked:  Triggers the action method on the <form> tag  Sends the form data (the name=value pair for each form element) to the web server.  Attributes:  type=“submit”  name  id  value
  • 17.
    17 XHTML<input /> Element ResetButton  Resets the form fields to their initial values  Attributes:  type=“reset”  name  id  value
  • 18.
    18 XHTML<input /> Element Button Offers a flexible user interface  There is no default action when the button is clicked  Usually a JavaScript function is invoked when a button is clicked  Attributes:  type=“button”  name  id  value
  • 19.
    19 XHTML<input /> Element Hiddenform data  This form element is not displayed on the web page.  Hidden form fields  Can be accessed by both client-side and server-side scripting  Sometimes used to contain information needed as the visitor moves from page to page.  Attributes:  type=“hidden”  name  id  value
  • 20.
  • 21.
    Checkpoint 9.1 1. Youare designing a web site for a client who sells items in a retail store. They want to create a customer list for e-mail marketing purposes. Your client sells to consumers and needs a form that accepts their customer’s name and e-mail address. Would you recommend using two input boxes (one for the name and one for the e-mail) or three input boxes (for the first name, last name, and email address)? Explain your answer. 21
  • 22.
    Checkpoint 9.1 2. Youare designing a survey form for a client. One of the questions has 10 possible responses. Only one response can be selected per question. What type of form element would you use to configure this question on the web page? 3. True or False. In a radio button group, the value attribute is used by the browser to process separate elements as a group. 22
  • 23.
    23 <form> <table border="0" width="75%"> <tr> <tdalign="right" width="10%">Name: </td> <td> <input type="text" name= "CustName" id= "CustName " size="30" /></td> </tr> <tr> <td align="right" width="10%">Email: </td> <td> <input type="text" name="CustEmail" id="CustEmail" /></td> </tr> <tr> <td align="right" width="10%"> <input type="submit" value="Submit" /></td> <td><input type="reset" /></td> </tr> </table> </form> XHTML Using a Table to Format a Form
  • 24.
    24 XHTML Form Enhancements <label>Element  Associates a text label with a form element  Two Different Formats: <label>Email: <input type="text" name="CustEmail" id ="CustEmail" /></label> Or <label for="email " >Email: </label><input type="text" name="CustEmail" id= "email " />
  • 25.
    25 XHTML Form Enhancements <fieldset>& <legend> elements  The Fieldset Element  Container tag  Creates a visual group of form elements on a web page  The Legend Element  Container tag  Creates a text label within the fieldset <fieldset><legend>Customer Information</legend> <label>Name: <input type="text" name="CustName" id="CustName" size="30" /></label><br /> <label>Email: <input type="text" name="CustEmail" id="CustEmail" /></label> </fieldset>
  • 26.
    26 XHTML Form Enhancements tabindexattribute  Attribute that can be used on form elements and anchor tags  Not supported by all browsers  Modifies the default tab order  Assign a numeric value <input type="text" name="CustEmail" id="CustEmail" tabindex="1" />
  • 27.
    27 XHTML Form Enhancements accesskeyattribute  Attribute that can be used on form elements and anchor tags  Not supported by all browsers  Create a “hot-key” combination to place the focus on the component  Assign a value of a keyboard letter  On Windows use the CTRL and the “hot- key” to move the cursor <input type="text" name="CustEmail" id="CustEmail" accesskey="E" />
  • 28.
    28 XHTML Form Enhancements <input/> Element Image Button  Submits the form  When clicked:  Triggers the action method on the <form> tag  Sends the form data (the name=value pair for each form element) to the web server.  Attributes:  type=“image”  name  id  src
  • 29.
    29 XHTML Form Enhancements <button>Element  A container tag  When clicked, its function depends on the value of the type attribute.  Can contain a combination of text, images, and media  Attributes:  type=“submit”, type=“reset”, type=“button”  name  id  alt  value
  • 30.
    30 Checkpoint 9.2 1. Describethe purpose of the fieldset and legend tags. 2. Describe the purpose of the accesskey attribute and how it supports accessibility. 3. When designing a form, should you use the standard submit button, an image button or a button tag? Are these different in the way that they provide for accessibility? Explain your answer.
  • 31.
    31 Using CSS to Stylea Form  Moderate Approach  Use a table to format the form but configure styles instead of XHTML table attributes. table { border: 3px solid #000000; width: 100%;} td { padding: 5px; margin: 0px;} .mylabel { text-align: right;}
  • 32.
    32 Using CSS to Stylea Form “Pure" CSS Approach  Do not use a table to format the form.  Use CSS divs and spans with positioning properties to configure the page. #myForm {border:3px solid #000000; padding:10px;margin:10px;} .myRow {height:30px;} .myRowComments {margin-bottom:20px;}
  • 33.
    33 Server-Side Processing  Your webbrowser requests web pages and their related files from a web server.  The web server locates the files and sends them to your web browser.  The web browser then renders the returned files and displays the requested web pages for you to use.
  • 34.
    34 CGI Common Gateway Interface A protocol for a web server to pass a web page user's request to an application program and accept information to send to the user.
  • 35.
    35 Steps in UtilizingCGI 1. Web page invokes CGI by a form action or hyperlink, etc...  Any form information is sent in the form of name=value pairs to the web server. 2. Script on web server is executed 3. Script accesses requested database, file, or process 4. Web server returns web page with requested information or confirmation of action
  • 36.
    36 Common Uses of Server-SideScripting & CGI  Search a database  Place an order at an online store  Send a web page to a friend  Subscribe to a newsletter  Any type of server-side file or e-mail processing is a candidate for CGI
  • 37.
    37 Checkpoint 9.3 1. DescribeCGI. 2. Code the form tag for a web page form that will use the post method to invoke a server-side script located at http://webdevfoundations.net/scripts/formdemo.asp
  • 38.
    38 Sources of Free Server-SideProcessing  Many web host providers offer free scripts for their clients. Contact their support area or FAQ to learn more about their services.  Some web sites that offer FREE remotely hosted scripts (in return for displaying an ad).  http://formbuddy.com  http://hostedscripts.com  http://response-o-matic.com  http://master.com  http://www.formmail.com  http://wufoo.com  http://iceberg.com  http://formassembly.com
  • 39.
    39 Languages that support CGI Programs or scripts that work with CGI can be written in many languages:  PHP  Perl  C  C++  Active Server Pages (ASP)  Java Server Pages (JSP)  ASP.NET  Ruby on Rails  And so on….
  • 40.
    40 Summary  This chapterintroduced the use of forms on web pages.  You learned about how to configure form elements and provide for accessibility.  You also learned about CGI and how to configure a form to access server-side processing.