Getting User Input with Forms

Slides:



Advertisements
Similar presentations
>> Introduction to HTML: Forms. Introduction to HTML 5 Important HTML Tags HTML tags and attributes Images Hyperlinks Lists –{ordered | unordered | definition}
Advertisements

CHAPTER 6 GETTING USER INPUT WITH FORMS. LEARNING OBJECTIVES Use the and tag pair to define an HTML-based form Use the tag to create a text box for user.
Video, audio, embed, iframe, HTML Form
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.
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.
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.
Unit 7 – Working with Forms 1. Creating a form 2. Accessing the submitted data 3. Common operations on forms.
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.
Forms and Form Controls Chapter What is a Form?
1 HTML Forms. 22 HTML forms provide a way for a user to send information back to the web server. Originally the user input was processed on the server.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
HTML Forms.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
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.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
1 Review of Form Elements. 2 The tag Used in between tags.  Form elements(text control, buttons, etc.. ) goes here. OR  Form elements(text control,
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.
SYST Web Technologies SYST Web Technologies XHTML Forms.
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.
HTML Form Inputs. Creating a basic form …content goes here…
1 HTML Forms. Objectives You will be able to: Compose HTML forms, to accept input from the user. Identify the different kinds of input tags that can appear.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
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.
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
Tutorial 6 Working with Web Forms
Web Development Part 2.
Client-Side Internet and Web Programming
Making your HTML Page Interactive
PHP: Forms FdSc Module 109 Server side scripting and Database design
How to Write Web Forms By Mimi Opkins.
Introduction to HTML Forms and Servlets
CS3220 Web and Internet Programming HTML Tables and Forms
Forms Web Design Ms. Olifer.
HTML Forms Pat Morin COMP 2405.
FORMS IN HTML.
>> More on HTML Forms
Introduction to Web programming
(and available form fields)
FORMS Explained By: Sarbjit Kaur.
HTML IV (Forms) Robin Burke ECT 270.
WHY FORMS? Explain: Mostly, when you need to collect data from a user you need a form Click: Google search form Click: Facebook login form Click:
ITE 115 Creating Web Page Forms
Lesson 8 Week 8 Designing Forms
Today - Forms! WD Students produce a basic HTML/XHTML document using forms. Find the group that best matches the part of the project you are going.
ARUSHA TECHNICAL COLLEGE WEB DESIGN(html forms)
HTML/XHTML Forms 18-Sep-18.
Designing Forms Lesson 10.
HTML: Basic Tags & Form Tags
Creating Form Elements
Creating Form Elements
Web Development & Design Foundations with H T M L 5
Forms Data Entry and Capture
FORM OBJECT When creating an interactive web site for the Internet it is necessary to capture user input and process this input. Based on the result of.
CNIT 131 HTML5 - Forms.
Web Development & Design Foundations with H T M L 5
CS3220 Web and Internet Programming HTML Tables and Forms
Basics of Web Design Chapter 10 Form Basics Key Concepts
HTML Forms 18-Apr-19.
© Hugh McCabe 2000 Web Authoring Lecture 8
Lesson 6: Web Forms.
Electronic Commerce HTML forms
Making your HTML Page Interactive
Unit 5 Create Forms.
HTML: Basic Tags & Form Tags
Presentation transcript:

Getting User Input with Forms Chapter 6 Getting User Input with Forms

Learning Objectives Use the <form> and </form> tag pair to define an HTML-based form Use the <input> tag to create a text box for user input within a form Use the <input> tag to create radio buttons which simplify user selection within a form Use the <input> tag to create checkboxes to allow users to select multiple options within a form Use the <input> tag to create a button within a form Use the <select> and </select> tag pair to define a pull-down list within a form Use the <textarea> and </textarea> tag pair to prompt the user for large amount of text within a form. Group related input fields within a form

Learning objectives continued Group related items within a pull-down list Submit a form’s contents to a remote script Compare and contrast server-side script validation of a form’s data with client- side JavaScript validation

Simple form – prompt only – no action <!DOCTYPE html> <html> <body> <form> Name: <input type="input" name="username"/> <br/><br/> E-Mail: <input type="input" name="e-mail"/> </form> </body> </html>

Submission process

Button, but still no submit <!DOCTYPE html> <html> <body> <form> Name: <input type="input" name="username"/> <br/><br/> E-Mail: <input type="input" name="e-mail"/> <br/><br/> <input type="submit" value="Click to Submit" /> </form> </body> </html>

Specifying the submit action <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> Name: <input type="input" name="username"/> <br/><br/> E-Mail: <input type="input" name="e-mail"/> <br/><br/> <input type="submit" value="Click to Submit" /> </form> </body> </html>

Formecho.php <?php $msg="Values submitted by the user:<br/>\n"; foreach($_POST as $key => $val){ if (is_array($val)){ $msg.="Item: $key<br/>\n"; foreach($val as $v){ $v = stripslashes($v); $msg.=" $v<br/>\n"; } } else { $val = stripslashes($val); $msg.="$key: $val<br/>\n"; } } echo $msg; ?>

Putting content into the form <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> <table> <tr><td><img src="http://www.websitedevelopmentbook.com/chapter06/Pasta.jpg" width="200" height="150"/></td> <td><img src="http://www.websitedevelopmentbook.com/chapter06/Pizza.jpg" width="200" height="150"/></td> <td><img src="http://www.websitedevelopmentbook.com/chapter06/Dessert.jpg" width="200" height="150"/></td> </tr> </table> <br/> What's Your Favorite Food: <input type="input" name="food"/> </body> </html>

Prompting for a password <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> Username: <input type="input" name="username"/> Password: <input type="password" name="userPassword"/> </body> </html>

Specifying field max lengths <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> Five: <input type="input" maxlength="5" size="5"/> Ten: <input type="input" maxlength="10" size="10"/> Twenty: <input type="input" maxlength="20" size="20"/> </form> </body> </html>

Using a textarea for larger input <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> Text Area: <textarea rows="10" cols="50"></textarea> </form> </body> </html>

Radio buttons <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> Gender: Male <input type="radio" name="gender" value="male"/> Female <input type="radio" name="gender" value="female"/> <br/><br/> PC Type: Windows <input type="radio" name="PC" value="Windows"/> Mac <input type="radio" name="PC" value="Mac"/> <br/><br/> <input type="submit" value="Click to Submit"/> </form> </body> </html>

Selecting a default radio button Male <input type="radio" name="gender" value="male" checked/> Female <input type="radio" name="gender" value="female"/>

Checkboxes <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> Desired Pizza Toppings: Cheese <input type="checkbox" name="cheese"/><br/> Pepperoni <input type="checkbox" name="pepperoni"/><br/> Bacon <input type="checkbox" name="bacon"/><br/> Pineapple <input type="checkbox" name="pineapple"/><br/> <br/><br/> <input type="submit" value="Click to Submit"/> </form> </body> </html>

Pull-down lists <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> Salutation: <select name=“salutation”> <option>Dr</option> <option>Mr</option> <option>Mrs</option> <option>Miss</option> <option>Ms</option> </select><br/><br/> Favorite Sport: <select name=“sport”> <option>Baseball</option> <option>Basketball</option> <option>Football</option> <option>Hockey</option> <option>Soccer</option> </select> <br/><br/> <input type="submit" value="Click to Submit"/> </form> </body> </html>

Pull-down list size Salutation: <select name="salutation" size= "5">

Selecting multiple elements Favorite Sport: <select name=“sport[]” multiple> <option>Baseball</option> <option>Basketball</option> <option>Football</option> <option>Hockey</option> <option>Soccer</option> </select>

Resetting a form’s contents <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> Name: <input type="input" name="name"/><br/> Phone: <input type="input" name="phone"/><br/> Programming Languages: C <input type="checkbox" name="C"/><br/> Java <input type="checkbox" name="Java"/><br/> VB <input type="checkbox" name="VB"/><br/><br/><br/> <input type="submit" value="Click to Submit"/><input type="reset" value="Reset"/> </form> </body> </html>

Creating a custom button <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.ph p" method="post"> <button type="submit"> <img src="http://www.WebsiteDevelopmentBook.com/Chapter06/clic k.jpg" height="100" width="100" /> </button> </form> </body> </html>

Using field labels <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> <label for="firstname"><b>First name:</b> </label> <input type="text" id="firstname"><br/> <label for="lastname"><b>Last name: </b></label> <input type="text" id="lastname"><br/> <label for="email"><i>email:</i> </label> <input type="text" id="email"><br/><br/><br/> <input type="submit" value="Click to Submit"/> </form> </body> </html>

E-mailing a form’s contents <!DOCTYPE html> <html> <body> <form action="mailto:SomeUser@SomeSite.com" method="post"> Name: <input type="input" name="username"/> <br/><br/> E-Mail: <input type="input" name="e-mail"/> <br/><br/> <input type="submit" value="Click to Submit" /> </form> </body> </html>

Hidden form fields <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> Name: <input type="input" name="username"/> <br/><br/> E-Mail: <input type="input" name="e-mail"/> <br/><br/> <input type="hidden" name="someField" value="1.2"/> <input type="submit" value="Click to Submit" /> </form> </body> </html>

Uploading a file <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/Chapter06/File Uploader.php" enctype="multipart/form-data" method="post"> File: <input type="file" name="file" id="file"/> <input type="submit" value="Submit" /> </form> </body> </html>

Processing a file upload with php <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo("Upload: " . $_FILES["file"]["name"] . " successful<br/>\n"); echo("Stored in: " . $_FILES["file"]["tmp_name"]); } ?>

Grouping fields <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> <fieldset> Name: <input type="input" name="username"/> <br/><br/> E-Mail: <input type="input" name="e-mail"/> </fieldset> <fieldset> Salutation: <select name=“salutation”> <option>Dr</option> <option>Mr</option> <option>Mrs</option> <option>Miss</option> <option>Ms</option> </select><br/><br/> Favorite Sport: <select name=“sport”> <option>Baseball</option> <option>Basketball</option> <option>Football</option> <option>Hockey</option> <option>Soccer</option> </select> </fieldset><br/> <input type="submit" value="Click to Submit" /> </form> </body> </html>

Grouping list selections <!DOCTYPE html> <html> <body> <form action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post"> Wines: <select name=“wine”> <optgroup label="White Wines"> <option>Chardonnay</option> <option>Pinot Grigio</option> <option>Sauvignon Blanc</option> </optgroup> <optgroup label="Red Wines"> <option>Cabernet Sauvignon</option> <option>Merlot</option> <option>Pinot Noir</option> </optgroup> </select> <input type="submit" value="Click to Submit" /> </form> </body> </html>

Real world: form validation <!DOCTYPE html> <head> <script> function validateForm() { if (document.forms["myForm"]["name"].value == null || document.forms["myForm"]["name"].value == "") { alert("Name must be filled out"); return false; } if (document.forms["myForm"]["phone"].value == null || document.forms["myForm"]["phone"].value == "") { alert("Phone must be filled out"); return false; } if (document.forms["myForm"]["email"].value == null || document.forms["myForm"]["email"].value == "") { alert("Email must be filled out"); return false; } return true; } </script> </head> <html> <body> <form name="myForm" action="http://www.WebsiteDevelopmentBook.com/FormEcho.php" method="post" onsubmit="return validateForm()" > Name: <input type="text" name="name" /><br/> Phone: <input type="text" name="phone" /><br/> E-mail: <input type="text" name="email" /><br/> <input type="submit" value="Click to Submit" /> </form> </body> </html>

Summary Depending on the processing a Web page performs, it is common for the page to require user input of some type. To perform such input operations, HTML pages use forms. Across the Web, sites use forms to prompt the user for login credentials, to request registration data, to get credit card and shipping information, and much more. You use the <form> and </form> tag pair to define a form and the <input> tag to create the most common form input fields. To perform form processing normally requires that one developer use HTML tags to create the form and that a second developer create scripts, using PHP or another scripting language, which process the data on the remote server.