Top Banner
Web Design Principles 5 th Edition Chapter Eleven Creating User Input Forms
49
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ppt ch11

Web Design Principles5th Edition

Chapter ElevenCreating User Input Forms

Page 2: Ppt ch11

Objectives

When you complete this chapter, you will be able to:

• Understand how forms work

• Use the <form> element

• Create input objects

• Style forms with Cascading Style Sheets (CSS)

2Web Design Principles 5th Ed.

Page 3: Ppt ch11

Understanding How Forms Work

Page 4: Ppt ch11

4

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

Web Design Principles 5th Ed.

Page 5: Ppt ch11

5

Understanding How Forms Work

• The data-processing software can then work with the data and send a response back to the user

• The user enters data via an HTML form

Web Design Principles 5th Ed.

Page 6: Ppt ch11

6Web Design Principles 5th Ed.

Page 7: Ppt ch11

Using the <form> Element

Page 8: Ppt ch11

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

8Web Design Principles 5th Ed.

Page 9: Ppt ch11

9Web Design Principles 5th Ed.

Page 10: Ppt ch11

10

Using the <form> element

• The following code shows a typical <form> element:

<form method="post"

action="https://signup.website.com/register.asp">

Web Design Principles 5th Ed.

Page 11: Ppt ch11

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

11Web Design Principles 5th Ed.

Page 12: Ppt ch11

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">

12Web Design Principles 5th Ed.

Page 13: Ppt ch11

Creating Input Objects

Page 14: Ppt ch11

14

Creating Input Objects

• The <input> element defines many of the form input object types

• The type attribute specifies the type of input object

Web Design Principles 5th Ed.

Page 15: Ppt ch11

15Web Design Principles 5th Ed.

Page 16: Ppt ch11

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>

16Web Design Principles 5th Ed.

Page 17: Ppt ch11

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>

17Web Design Principles 5th Ed.

Page 18: Ppt ch11

18

Creating Text Boxes

• The text box is the most commonly used form element

<input type="text" name="firstname" size="20" maxlength="35" value="First Name">

Web Design Principles 5th Ed.

Page 19: Ppt ch11

19Web Design Principles 5th Ed.

Page 20: Ppt ch11

20

Creating Check Boxes

• Check boxes are an on/off toggle that the user can select

<input type="checkbox" name="species" value="smbass"> Smallmouth Bass

Web Design Principles 5th Ed.

Page 21: Ppt ch11

21Web Design Principles 5th Ed.

Page 22: Ppt ch11

22

Creating Radio Buttons

• Radio buttons are like check boxes, but only one selection is allowed

<p>Would you like to be on our mailing list?</p>

<p><input type="radio" name="list" value="yes"

id="Yes" />

<label for="Yes">Yes</label>

<input type="radio" name="list" value="no"

id="No" />

<label for="No">No</label>• </p>

Web Design Principles 5th Ed.

Page 23: Ppt ch11

23Web Design Principles 5th Ed.

Page 24: Ppt ch11

24

Creating Submit & Reset Buttons

• The submit and reset buttons let the user choose whether to send the form data or start over

<input type="submit" value="Submit your answers">

<input type="reset" value="Clear the form">

Web Design Principles 5th Ed.

Page 25: Ppt ch11

25Web Design Principles 5th Ed.

Page 26: Ppt ch11

26

Creating an Image for the Submit Button

• You can choose an image file and use it instead of the default submit button

<input type="image" src="submit.gif" alt="submit button">

Web Design Principles 5th Ed.

Page 27: Ppt ch11

27Web Design Principles 5th Ed.

Page 28: Ppt ch11

28

Letting the User Submit a File

• Users can select a file on their own computer and send it to the server

<p>Use the browse button to select your file:</p>

<p><input type="file" size="30“></p>

Web Design Principles 5th Ed.

Page 29: Ppt ch11

29Web Design Principles 5th Ed.

Page 30: Ppt ch11

30

Creating a Password Entry Field

• The password input box works like the text input, but the entered text is hidden by asterisks

<p>Enter your user name and password:</p>

<p>

User Name: <input type="text" size="30" />

Password: <input type="password" size="30" />

</p>

Web Design Principles 5th Ed.

Page 31: Ppt ch11

31Web Design Principles 5th Ed.

Page 32: Ppt ch11

32

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>

Web Design Principles 5th Ed.

Page 33: Ppt ch11

33Web Design Principles 5th Ed.

Page 34: Ppt ch11

34

Using the <select> Element

• You can choose to let the user pick multiple values from the list by adding the multiple attribute

<select name="snacks" multiple size="6"><option>Potato Chips</option><option>Popcorn</option><option>Peanuts</option><option>Pretzels</option><option>Nachos</option><option>Pizza</option><option>Fries</option>

</select>

Web Design Principles 5th Ed.

Page 35: Ppt ch11

35Web Design Principles 5th Ed.

Page 36: Ppt ch11

36

Using the <select> Element

• You group and label sets of list options with the <optgroup> element and label attribute

<optgroup label="Salty Snacks"><option>Potato Chips</option><option>Popcorn</option><option>Peanuts</option><option>Pretzels</option>

</optgroup>

Web Design Principles 5th Ed.

Page 37: Ppt ch11

37Web Design Principles 5th Ed.

Page 38: Ppt ch11

38

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>

Web Design Principles 5th Ed.

Page 39: Ppt ch11

39Web Design Principles 5th Ed.

Page 40: Ppt ch11

40

Creating Input Groupings

• You can use the <fieldset> and <legend> elements to create groupings of different types of input elements

Web Design Principles 5th Ed.

Page 41: Ppt ch11

41

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>

Web Design Principles 5th Ed.

Page 42: Ppt ch11

42Web Design Principles 5th Ed.

Page 43: Ppt ch11

Styling Forms with CSS

Page 44: Ppt ch11

44

Styling Forms with CSS

• You can use many of the CSS properties to specify type styles, background colors, box properties, and colors to enhance the look of your forms

• The grouping and labeling elements <fieldset>, <legend>, and <label> are useful when applying styles to forms

Web Design Principles 5th Ed.

Page 45: Ppt ch11

45Web Design Principles 5th Ed.

Page 46: Ppt ch11

46Web Design Principles 5th Ed.

Page 47: Ppt ch11

47Web Design Principles 5th Ed.

Page 48: Ppt ch11

48Web Design Principles 5th Ed.

Page 49: Ppt ch11

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

49Web Design Principles 5th Ed.