XHTML Forms for Data Collection and Submission Chapter 5.

Slides:



Advertisements
Similar presentations
HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
Advertisements

Tutorial 6 Creating a Web Form
Chapter 6 Basic forms 1. Forms and query string 2 form : a group of user input (UI) controls that accepts information from the user and sends the information.
SE-2840 Dr. Mark L. Hornick 1 HTML input elements and forms.
Capturing user input: Using HTML FORMs User input Up till now, our HTML documents have all been directed at outputting information to the user However,
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
Tutorial 6 Working with Web Forms
Forms Review. 2 Using Forms tag  Contains the form elements on a web page  Container tag tag  Configures a variety of form elements including text.
Capturing user input: Using HTML FORMs CS4320 got here on 27/11/2003.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Table, Forms, Metatags and Frames.
Session 2 Tables and forms in HTML Adapted by Sophie Peter from original document by Charlie Foulkes.
Creating Web Page Forms
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
Forms and Form Controls Chapter What is a Form?
1 XHTML Forms A form is the mechanism to –Collect information from a browser user –Transmit collected information from a browser to a server HTML/XHTML.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
INTRODUCTORY Tutorial 8 Creating Forms. XP New Perspectives on Blended HTML, XHTML, and CSS2 Objectives Create an HTML form Create fields for text Create.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
HTML Forms.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
Introduction to HTML Part 3 Chapter 2. Learning Outcomes Identify how to design frames. Explain frames’ attributes. Describe the method on designing forms.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input.
1 HTML Forms
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
HTML Forms a form is a container for input elements on a web page input elements contain data that is sent to the web server for processing.
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
TJ 3043 – Web Application Development HTML Form. 2.0 Forms - A form is the usual way information is gotten from a browser to a server - HTML has tags.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
+ FORMS HTML forms are used to pass data to a server. begins and ends a form Forms are made up of input elements Every input element has a name and value.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Project 6 Creating Forms on a Web Page. Objectives Define terms related to forms Describe the different form controls and their uses Use the tag Create.
HTML Forms.
1 HTML Forms
Copyright (c) 2004 Prentice-Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Project 6: Creating XHTML Forms Kelly.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Tutorial 6 Creating a Web Form
Web Forms. Web Forms: A form allows our web visitors to submit information to us. Some examples uses for forms are to let the web user contact us, fill.
Lesson 5 Introduction to HTML Forms. Lesson 5 Forms A form is an area that can contain form elements. Form elements are elements that allow the user to.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Tutorial 6 Working with Web Forms
Creating and Processing Web Forms
Client-Side Internet and Web Programming
Objectives Design a form Create a form Create text fields
FORMS IN HTML.
XHTML Forms for Data Collection and Submission
Introducing Forms.
HTML Forms and User Input
Unit I: Collecting Data with Forms
© Hugh McCabe 2000 Web Authoring Lecture 8
Presentation transcript:

XHTML Forms for Data Collection and Submission Chapter 5

Overview and Objectives The use of web forms to collect data input by users The XHTML form element and its action and method attributes These XHTML “form controls” (also called “widgets”) – the input element – the select and option elements – the textarea element – the submit and reset buttons – the fieldset and legend elements – the label element and its for attribute Setting up two forms: – a Body Mass Index calculator form – a user feedback form Getting ready to submit form data (but not actually submitting it) This chapter is a “standalone” chapter on forms, and we do not incorporate them into our Nature’s Source website until Chapter 8. Chapter 5: XHTML Forms for Data Collection and Submission

Why Forms? Forms are just a fact of everyday life: employment applications, income tax forms, forms to tell the doctor the state of our health … A website will often need to collect information from a visitor, especially if it hopes to do business with that visitor. Thus the need for forms on our websites parallels our need for them in everyday life. Online forms appear in various guises, but often look just like the paper forms we use. Here are the three main aspects to the use of forms for collecting user data: – Designing an appropriate form to collect the desired data (this chapter) – Ensuring the data entered is the data you want (Chapter 6) – Submitting the data to a server for processing (Chapter 8) Chapter 5: XHTML Forms for Data Collection and Submission

The XHTML form Element and Its action and method Attributes To place a form on a web page we begin by inserting an XHTML form element at the appropriate location in our page markup. The form element by itself has no visual effect on the page display. Data-collection elements such as input and textarea are nested inside the form element. Both the form element itself and the data-collection elements it contains can be styled with CSS. A form element will also contain a submit button which a user will click to “submit” the form data. The form tag has an action attribute whose value says what to do when the submit button is activated. In this chapter we will essentially ignore the action attribute and simply assign the empty string as its value. The form tag also has a method attribute whose value may be GET or POST, indicating how the data will be transferred to the server. We ignore that attribute as well in this chapter. Chapter 5: XHTML Forms for Data Collection and Submission

A Body Mass Index (BMI) Calculator Our first form will be used to compute a user’s body mass index. A person’s body mass index is a quantity computed from that person’s height and weight. BMI can be used as an indicator of total body fat. For more information and the formula on which our calculator is based see the website of the National Institute of Health: Chapter 5: XHTML Forms for Data Collection and Submission

First Pass at a BMI Calculator: Display of bmi1.html with Its Empty form Element Chapter 5: XHTML Forms for Data Collection and Submission Courtesy of Nature’s Source.

Markup from bmi1.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " Body Mass Index Calculator Body Mass Index Calculator Body Mass Index (BMI) is used as an indicator of total body fat. Total body fat is correlated to the risk of... Chapter 5: XHTML Forms for Data Collection and Submission

Second Pass at a BMI Calculator: Display of bmi2.html Chapter 5: XHTML Forms for Data Collection and Submission Courtesy of Nature’s Source.

The XHTML input Element The XHTML input element is an empty element only used inside a form element. Each input element creates, in the form display, a form field (a place where the user can enter data or indicate a choice). A typical form will have several input elements allowing the user to – Enter a line of text (a different element is used for more text) – Choose one from several mutually exclusive alternatives – Choose one or more from several alternatives that are not mutually exclusive – Indicate whether a single option has been chosen or not All input elements have these attributes: – A type attribute whose value determines what kind of input element it will be – A value attribute which is used in different ways, depending on the kind of input element being used – A name attribute which can be used to refer to the element in a script Additional informational text must be present so that a user will know exactly what a particular input element is expecting. Chapter 5: XHTML Forms for Data Collection and Submission

The input Element with type="text" This input element allows the user to enter a single line of text. – Example: The size attribute specifies the visible width, in characters, of the text box display (default value is 20). More characters than the visible number may be entered. For this input element a value attribute could be used to supply a “default” value to appear in the text box until a user starts typing in that box. See the text boxes labeled Height: and Weight: in the display of bmi2.html. Chapter 5: XHTML Forms for Data Collection and Submission

The input Element with type="radio" This input element allows the user to choose one of several mutually exclusive alternatives. – Example: All input elements with type="radio" and with the same value for the name attribute form a group, of which only one may be selected. Select another one, and the previously selected choice will be “de-selected”. The (required, in this case) value attribute contains the data transmitted from this input element when this form is submitted to a server. See the “radio buttons” labeled inches and pounds in the display of bmi2.html. Chapter 5: XHTML Forms for Data Collection and Submission

The input Element with type="checkbox" This input element allows the user to make one or more choices from one or more (non-mutually-exclusive) alternatives. It can also be used to indicate whether a single option has been chosen or not. – Example: All input elements with type="checkbox" and with the same value for the name attribute form a group, from which any number may be selected. The (also required) value attribute contains the data transmitted from this input element when this form is submitted to a server. See the option for getting a detailed BMI analysis in bmi2.html. Chapter 5: XHTML Forms for Data Collection and Submission

Form Markup from bmi2.html : Shows text, radio, and checkbox input Elements Height: Units: inches centimeters Weight: Units: pounds kilograms Please check here if you want a detailed analysis of your BMI: <input type="checkbox" name="details" value="yes" /> Chapter 5: XHTML Forms for Data Collection and Submission

Third Pass at a BMI Calculator: Display of bmi3.html Chapter 5: XHTML Forms for Data Collection and Submission Now using dropdown lists Courtesy of Nature’s Source.

The select and option Elements for Dropdown List-boxes The select and option elements only appear within a form element and combine to produce a dropdown list-box – Example inches centimeters Each option element is nested within a select element. The first option element is the one that appears in the display of the dropdown list-box. See the dropdown list boxes showing inches and pounds in the display of bmi3.html. Chapter 5: XHTML Forms for Data Collection and Submission

Form Markup from bmi3.html Showing select and option Elements Height: Units: inches centimeters Weight: Units: pounds kilograms Chapter 5: XHTML Forms for Data Collection and Submission

The Missing Element from Our BMI Calculator Our BMI calculator contains form fields for the user to enter or choose all the necessary information for the calculation. But … when and how is that calculation going to be performed? We are missing a button (another input element) which the user can click to cause the calculation to be performed and the result displayed. We postpone the discussion of such a button temporarily until we have introduced a second form. Chapter 5: XHTML Forms for Data Collection and Submission

Collecting User Feedback Our second form will be used to collect feedback from the visitors to our website. Such forms are found on many websites, and typically contain form fields for the following: – The user’s name, address, gender, telephone number(s), address(es), and possibly additional personal information – A place for the user to enter comments about the company’s website or to ask questions Most of these form fields can be handled by the elements we already know about, but for comments and/or extended feedback we need a new element. Chapter 5: XHTML Forms for Data Collection and Submission

First Pass at a Feedback Form: Display of feedback1.html Chapter 5: XHTML Forms for Data Collection and Submission Courtesy of Nature’s Source.

The textarea Element The XHTML textarea element only appears within a form element, and can be used to collect text when we want the user to enter more than will fit on a single line. – Example: The rows and cols attributes determine the number of text lines and character columns in the display area where the user is to start typing. If the user enters more text than allowed for by the values of rows and cols, the textarea box will a provide scroll bar as appropriate. See the textarea box labeled Comments: in the display of feedback1.html. Chapter 5: XHTML Forms for Data Collection and Submission

Partial form markup from feedback1.html Subject: Comments: Please check here if you wish to receive a reply: Chapter 5: XHTML Forms for Data Collection and Submission

Second Pass at a Feedback Form Display of feedback2.html Chapter 5: XHTML Forms for Data Collection and Submission Courtesy of Nature’s Source.

The input Elements of Type submit and reset Finally we have two buttons the user can click to make something happen: – A “submit button” to send the form data to the server (remember, though, we are not actually doing that in this chapter): – A “reset button” if the user wishes to clear the form input and start over: In both cases the value attribute determines the text that will appear on the button in the browser display. See the Send Feedback and Reset buttons in the display of feedback2.html. Chapter 5: XHTML Forms for Data Collection and Submission

Partial form Markup from feedback2.html Comments: Please check here if you wish to receive a reply: Chapter 5: XHTML Forms for Data Collection and Submission

Fourth Pass at a BMI Calculator Display of bmi4.html (or bmi5.html ) Chapter 5: XHTML Forms for Data Collection and Submission Courtesy of Nature’s Source.

Organizing Form Controls (Form Fields) with the fieldset and legend Elements Often it is helpful to the user if form fields are arranged in logical groupings on the form display. The fieldset element allows us to group a set of form controls and have the browser place a “box outline” around the grouping. The legend element allows us to name, or provide a label for, such a grouping, and it must be placed directly inside the fieldset element with which it is associated. The content of the legend element will appear on the top left part of the box border produced by the fieldset element. See the result of using the fieldset and legend elements in the display of bmi4.html (or bmi5.html, which has exactly the same display, and so is not shown here). Chapter 5: XHTML Forms for Data Collection and Submission

One Fieldset Markup from bmi4.html Vital statistics Height: Units: inches centimeters Weight: Units: pounds kilograms Please check here if you want a detailed analysis of your BMI: Chapter 5: XHTML Forms for Data Collection and Submission

Behind-the-scenes Logical Groupings for Usability with the label Element The XHTML label element has no visual effect on a form display. It is used to associate a text label with its corresponding input element. The association is achieved by making the value of the label element’s for attribute the value of the id attribute of the corresponding input element. This association is a usability feature, since it allows the (usually text) label itself to be clicked to move the focus to its corresponding input element. That is, the user is not forced to click directly on the input element itself. This difference cannot be illustrated in a static display. Instead the difference in behavior must be “experienced” by comparing the behavior of bmi4.html (which has no label elements) and bmi5.html (which does, but in every other respect is just like bmi4.html ) when each is viewed in a browser and the user clicks on a text label for one of the form fields. For example, when bmi5.html is displayed, click anywhere on the text of the “Please check here … ” instruction to see what happens. Chapter 5: XHTML Forms for Data Collection and Submission

Partial form Markup from bmi5.html Illustrating the label Element Height: <input id="height" type="text" name="height“ size="7" /> Units: inches centimeters Chapter 5: XHTML Forms for Data Collection and Submission

Are We Ready to Submit Our Form Data? We now have two forms (a BMI calculator form and a feedback form) capable of collecting all the data we need for each purpose. But … are we ready to submit that data to a server for processing? Not quite … before we submit that data we want to make sure the data we asked for is the data we got from the user. And as for the BMI calculation, we will eventually ask the server to do it, but in the meantime we will see how it can actually be done on the client side without sending the information to the server. These are our topics of discussion in the next chapter. Chapter 5: XHTML Forms for Data Collection and Submission