Understanding and Using Web Forms
Understanding and Using Web Forms
6th Edition
2
Understanding How Forms Work
3
Understanding How Forms Work
• Forms let you build interactive web pages that
collect information from a user and process it
on the web server
• The HTML form is the interface for the user to
enter data
• The data is processed by applications that
reside on the web server
4
Understanding How Forms Work
5
6
Using the <form> Element
7
Using the <form> element
• The <form> element is the container for creating a
form
• A variety of attributes describe how the form data
will be processed
8
9
Using the <form> element
<form method="post"
action="https://signup.website.com/register.asp">
10
Using get or post
• The difference between get and post is the
way the data is sent to the server
• method=“get”: this method sends the form
information by including it in the URL
• method=“post”: this method sends the form
information securely to the server within the
message body
11
Using the mailto Action
• Lets you collect data from a form and send it
to any e-mail address
<form action="mailto:joel@joelsklar.com"
method="post" enctype="text/plain">
12
Creating Input Objects
13
Creating Input Objects
14
15
16
Labeling Form Elements
• The <label> element lets you create a caption
for an input element
• Lets you extend the clickable area of a form
element
<p>
<label class="username" >First Name:</label>
<input type="text" name="firstname"
size="35" maxlength="35" />
</p>
17
Labeling Form Elements
• To make the text clickable, you associate the
<label> element with the <input> element by
using the for and id attributes
<p>
<label class="username" for="First Name">
First Name:</label>
<input type="text" name="fi rstname" id="First
Name"
size="35" maxlength="35" />
</p>
18
Creating Text Boxes
19
20
Creating Check Boxes
21
22
Creating Radio Buttons
• Radio buttons are like check boxes, but only one
selection is allowed
23
24
Creating Submit & Reset Buttons
• The submit and reset buttons let the user choose
whether to send the form data or start over
25
26
Creating an Image for the
Submit Button
• You can choose an image file and use it instead of
the default submit button
27
28
Letting the User Submit a File
29
30
Creating a Password Entry Field
31
32
Creating a Password Entry Field
33
34
Using the <select> Element
• The <select> element lets you create a list box or
scrollable list of selectable options
<select name="boats">
<option>Canoe</option>
<option>Jon Boat</option>
<option>Kayak</option>
<option>Bass Boat</option>
<option>Family Boat</option>
</select>
35
36
Using the <select> Element
• You can choose to let the user pick multiple values
from the list by adding the multiple attribute
39
40
Using the <textarea> Element
• The <textarea> element lets you create a larger
text area for user input
<p><b>Briefly tell us your favorite fish
story:</b><br>
<textarea name="fishstory" rows="5"
cols="30">
Enter your story here...
</textarea>
</p>
41
42
Creating Input Groupings
• You can use the <fieldset> and <legend> elements to
create groupings of different types of input elements
43
Creating Input Groupings
<fieldset>
<legend><b>Select the species you prefer
to fish:</b></legend>
<input type="checkbox" name="species"
value="smbass"> Smallmouth Bass
<input type="checkbox" name="species"
value="lgbass"> Largemouth Bass <br>
<input type="checkbox" name="species"
value="pike"> Pike
</fieldset>
44
45
Styling Forms with CSS
46
47
48
49
50
51
52
53
Summary
• Choose the right form elements based on the
data you want to collect
• A form element has attributes that describe how
the form data is processed
• You need a server application to process your
form data
• The <fieldset> and <legend> elements let you
create more visually appealing forms
• Forms should be formatted to improve their
legibility
54