Web development lecture CH11
Web development lecture CH11
6th Edition
2
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
3
Understanding How Forms Work
4
5
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
6
7
Using the <form> element
<form method="post"
action="https://signup.website.com/register.asp">
8
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
9
Using the mailto Action
• Lets you collect data from a form and send it
to any e-mail address
<form action="mailto:[email protected]"
method="post" enctype="text/plain">
10
Creating Input Objects
11
12
13
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>
14
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>
15
Creating Text Boxes
16
17
Creating Check Boxes
18
19
Creating Radio Buttons
• Radio buttons are like check boxes, but only one
selection is allowed
20
21
Creating Submit & Reset Buttons
• The submit and reset buttons let the user choose
whether to send the form data or start over
22
23
Creating an Image for the
Submit Button
24
25
Letting the User Submit a File
26
27
Creating a Password Entry Field
28
29
Creating a Password Entry Field
30
31
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>
32
33
Using the <select> Element
• You can choose to let the user pick multiple values
from the list by adding the multiple attribute
36
37
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>
38
39
Creating Input Groupings
• You can use the <fieldset> and <legend> elements to
create groupings of different types of input elements
40
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>
41
42
Styling Forms with CSS
43
44
45
46
47
48
49
50
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
51