Basics of Web Design: Form Basics - Chapter 10 PDF
Document Details

Uploaded by IndebtedOwl
2022
Terry Ann Morris
Tags
Summary
This chapter from "Basics of Web Design" introduces the use of forms on web pages, covering form elements, styling with CSS, and server-side processing. It also explores various HTML5 form controls and attributes. This document is designed to guide students creating interactive web pages with a focus on form design and functionality.
Full Transcript
Basics of Web Design Chapter 10 Form Basics Basics of Web Design: HTML5 & CSS, 6th Edition Copyright © 2022 Terry Ann Morris, Ed.D. https://terrymorris.net 1 Learning Outcomes Describe common uses of forms on web...
Basics of Web Design Chapter 10 Form Basics Basics of Web Design: HTML5 & CSS, 6th Edition Copyright © 2022 Terry Ann Morris, Ed.D. https://terrymorris.net 1 Learning Outcomes Describe common uses of forms on web pages Create forms on web pages using the form, input, textarea, and select elements Associate form controls and groups using label, fieldset, and legend elements Use CSS to style a form Use Grid Layout to style a form Use CSS Flexbox to style a form Describe the features and common uses of server-side processing Invoke server-side processing to handle form data Configure new HTML5 form controls and attributes 2 Copyright © 2022 Terry Ann Morris, Ed. D. 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… 3 Copyright © 2022 Terry Ann Morris, Ed. D. Two Components of Using Forms 1. The web page form An HTML element that contains and organizes form controls such as text boxes, check boxes, and buttons that can accept information from website visitors. and 2. The server-side processing Server-side processing 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. 4 Copyright © 2022 Terry Ann Morris, Ed. D. tag Contains the form elements on a web page HTM Container tag L tag Form Configures a variety of form elements including text boxes, radio buttons, check boxes, and buttons s Stand alone tag tag Configures a scrolling text box Container tag tag Configures a select box (drop down list) Container tag tag Configures an option in the select box Container tag 5 Copyright © 2022 Terry Ann Morris, Ed. D. Sample Form HTML E-mail: 6 Copyright © 2022 Terry Ann Morris, Ed. D. The Form Element Container Tag The form element 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 7 Copyright © 2022 Terry Ann Morris, Ed. D. The Input Element Text Box Accepts text information Common Attributes: type="text" name id size maxlength value required placeholder 8 Copyright © 2022 Terry Ann Morris, Ed. D. The Input Element Check box Allows the user to select one or more of a group of predetermined items Common Attributes: type="checkbox" name id checked value 9 Copyright © 2022 Terry Ann Morris, Ed. D. The 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 Common Attributes: type="radio" name id checked value 10 Copyright © 2022 Terry Ann Morris, Ed. D. The Textarea Element Configures a scrolling text box Common Attributes: name id cols rows required 11 Copyright © 2022 Terry Ann Morris, Ed. D. The Select Element Configures a select list (along with 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. Common Attributes: name id size multiple 12 Copyright © 2022 Terry Ann Morris, Ed. D. The Option Element Configures the options in a Select List Attributes: value selected 13 Copyright © 2022 Terry Ann Morris, Ed. D. The Input Element Submit Button Submits the form information When clicked: Triggers the action method on the tag Sends the form data (the name=value pair for each form element) to the web server. Attributes: type="submit" name id value 14 Copyright © 2022 Terry Ann Morris, Ed. D. The Input Element Reset Button Resets the form fields to their initial values Attributes: type="reset" name id value 15 Copyright © 2022 Terry Ann Morris, Ed. D. The Input Element Hidden Field This form control is not displayed on the Web page. Hidden form fields Can be accessed by both client-side and server-side scripting Common Attributes: type="hidden" name id value 16 Copyright © 2022 Terry Ann Morris, Ed. D. Input Element File Upload Control Accepts a file upload when the form is submitted Requires the form element to be configured with method="post" enctype="multipart/form-data" and the action attribute. Attributes: type="file" name id accepts capture multiple Copyright © 2022 Terry Ann Morris, Ed. D. 17 The Input Element Password Box Accepts text information that needs to be hidden as it is entered Common Attributes: type="password" name id size maxlength value required placeholder 18 Copyright © 2022 Terry Ann Morris, Ed. D. The Label Element Associates a text label with a form control Two Different Formats: Email: id ="CustEmail"> OR Email: 19 Copyright © 2022 Terry Ann Morris, Ed. D. The Fieldset & Legend Elements The Fieldset Element Container tag Creates a visual group of form controls on a web page The Legend Element Container tag Creates a text label within the fieldset Customer Information Name: Email: 20 Copyright © 2022 Terry Ann Morris, Ed. D. Using CSS to Style a Form form { background-color:#EAEAEA; font-family: Arial, sans-serif; width: 350px; padding: 10px;} label { float: left; clear: left; display: block; width: 100px; text-align: right; padding-right: 10px; margin-top: 10px; } input, textarea { margin-top: 10px; display: block;} input[type= "submit"]{ margin-left: 110px; } 21 Copyright © 2022 Terry Ann Morris, Ed. D. Using CSS Grid Layout to Style a Form form { display: grid; grid-template-rows: auto; grid-template-columns: 6em 1fr; grid-gap: 1em; gap: 1em; background-color: #EAEAEA; font-family: Arial, sans-serif; width: 60%; min-width: 20em; padding: 2em; } input[type="submit"] { grid-column: 2 / 3; width: 10em; } 22 Copyright © 2022 Terry Ann Morris, Ed. D. 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. 23 Copyright © 2022 Terry Ann Morris, Ed. D. Server-Side Scripting One of many technologies in which a server-side script is embedded within a web page document saved with a file extension such as:.php (PHP).jsp (Sun JavaServer Pages).aspx (ASP.Net) Uses direct execution — the script is run either by the web server itself or by an extension module to the web server. 24 Copyright © 2022 Terry Ann Morris, Ed. D. HTML5: Email Text Box Accepts text information in e-mail address format Common Attributes: type="email" name id size maxlength value placeholder required 25 Copyright © 2022 Terry Ann Morris, Ed. D. HTML5: URL Text Box Accepts text information in URL format Common Attributes: type="url" name id size maxlength value placeholder required 26 Copyright © 2022 Terry Ann Morris, Ed. D. HTML5: Telephone Number Text Box Accepts text information in telephone number format Common Attributes: type="tel" name id size maxlength value placeholder required 27 Copyright © 2022 Terry Ann Morris, Ed. D. HTML5: Search Text Box Accepts search terms Common Attributes: type="search" name id size maxlength value placeholder required 28 Copyright © 2022 Terry Ann Morris, Ed. D. HTML5: Datalist Control Favorite Color: red green blue yellow pink black