HTML Forms and User Input

Slides:



Advertisements
Similar presentations
Tutorial 6 Creating a Web Form
Advertisements

Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
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.
Python and Web Programming
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.
Creating Web Page Forms
Forms. Form An HTML form is a section of a document containing normal content, special elements called controls (checkboxes, radio buttons, buttons, etc.),
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.
MS3304: Week 4 PHP & HTML Forms. Overview HTML Forms elements refresher Sending data to a script via an HTML form –The post vs. get methods –Name value.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
CO1552 Web Application Development HTML Forms. Websites can be made more interactive by providing facilities for users to provide data To get user entered.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
Forms and Form Controls Chapter What is a Form?
DAT602 Database Application Development Lecture 14 HTML.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
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.
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.
HTML : Forms, Frames Instructor: Mr. Ahmed Al Astal ITGD4104 Department Requirement for senior student University of Palestine Faculty of IT.
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
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.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
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.
Web Forms. Survey or poll Contact us Sign up for an newsletter Register for an event Submit comments or feedback about our site Log in to a members-only.
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.
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.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
HTML Forms. A form is simply an area that can contain form fields. Form fields are objects that allow the visitor to enter information - for example text.
20-753: Fundamentals of Web Programming 1 Lecture 6: Advanced HTML Fundamentals of Web Programming Lecture 6: Advanced HTML.
Tutorial 6 Creating a Web Form
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.
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.
XHTML Forms.
Tutorial 6 Working with Web Forms
Creating and Processing Web Forms
Web Forms.
Web Forms.
How to Write Web Forms By Mimi Opkins.
Loops BIS1523 – Lecture 10.
Objectives Design a form Create a form Create text fields
Arrays and files BIS1523 – Lecture 15.
Intro to PHP & Variables
Cookies BIS1523 – Lecture 23.
Introducing Forms.
More Selections BIS1523 – Lecture 9.
Functions BIS1523 – Lecture 17.
Number and String Operations
In-Class Program: Sales System
Web Development & Design Foundations with H T M L 5
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.
Forms, cont’d.
In Class Programming BIS1523 – Lecture 11.
In Class Programming: Credit card payment
CNIT 131 HTML5 - Forms.
Lesson 6: Web Forms.
PHP-II.
Web Forms.
Presentation transcript:

HTML Forms and User Input BIS1523 – Lecture 5

The 2-Page Model for Input In web based programming, HTML web pages can be used to allow the user to input data for processing. The data the user entered is then sent to a page with PHP that can read it in, process it, and send out the results.

Two Page Model Our starting programs will follow this 2 page model. We will have one page that is HTML, and has areas that allow user input. In this example it is tempconv.html The second page will be our PHP program that displays results. In this example it is results.php We may also include a .css file for styling of both pages…

Form Tag To allow a user to input data, we use a <form> element Each of your elements that allow the user to input stuff should be between the <form> and </form> tags. The form tag also contains an action attribute, this is the attribute that tells the form where the PHP program that will process the input is.

Form Method There are 2 possible values for the “method” attribute of a form, they are GET or POST The differences are: With the GET method, a limited amount of information can be passed. The GET method sends the data to the handling script publicly (which means, for example, that a password entered in a form would be viewable by anyone within eyesight of the Web browser, creating a larger security risk). A page using a GET method can be bookmarked, a POST method cannot be Users will be prompted if they attempt to reload a POST page We will use POST for the majority of this course

Input Tag The <input> tag is used to place several different kinds of elements into your form. It has several attributes associated with it: Type describes what type of input you will use, text, radio buttons, submit button, etc. Name gives the input a name. Every input needs to have a unique name. Size is optional, but can be used to determine how big the area is displayed on the screen The “text” type allows the user to type a single line of text as input

Submit Button In order to process a form, there also needs to be a submit element on it. type “submit” is a button that will trigger the call to the PHP program Name needs to be unique Value is the text that is printed on the button When the user clicks the Go! Button, it will load “results.php”, passing information from inputs to that PHP program.

Retrieving Values in PHP Values sent to a PHP program from a form are stored in one of two specially named variables: $_GET or $_POST The variable you use depends on if you used GET or POST method in the HTML file. (We will use POST) in this class. The syntax for accessing these values is: $_POST[<name of item to retrieve>] The name you use was the name of the input in the HTML form. So to retrieve the name in our previous example, you could access the variable $_POST[‘name’]

Reading and Printing The Data In our example, we had a single input called “name” We can read it in in our results.php, and store it in a variable called $name Then print that variable back out again.

Select Tag The <select> tag is used to create a drop-down list for the user to select a single option from. The opening <select> tab should include a (unique) name attribute Within the select are any number of <option> tags. The option tags have a “value” attribute, and will surround the text they will display.

Select When the form is submitted, the value of “classification” will be set to the “value” attribute from whatever the user selected. So if, for example, the user selected “staff”, and we did the PHP command: $class = $_POST[‘classification’] The variable $class would have the value “staff”

Textarea <textarea> is a multi line input. It has the following attributes: Name to identify it Rows and cols determine how big it is on the screen Any text between the starting and ending tags will appear as the ‘default’ text in the area. This can be left blank.

Retrieving a textarea A textarea can be retrieved as a string just like a normal one line text value can be.

Radio Buttons Radio buttons allow the user to select one from several options. A group of radio buttons with the same name will be mutually exclusive. Each button will have a value attribute, this is the value of the ‘name’ field that will be passed to PHP when the form is submitted

Radio Button Values Since you grouped the radio buttons with the same name, you can use that name in the POST variable to retrieve the value of which button the user selected.

Combining PHP with CSS Since the output of our PHP programs is HTML, we can also incorporate CSS to improve the look of our layout. This might include grouping sections of HTML together with ID or Class, and adjusting their colors, location, borders, etc. Example Notes: added some headings, and a box for our content with PHP and CSS. Include necessary tags and ID attributes to accomplish this You may need to escape double quotes to print them.

Final Results PHP and CSS

Finished Input Screen

Input Tag Summary Input Tag Use Notes <input type=“text”> A single line of input <input type=“submit”> The button to submit the form The “value” field is printed on the screen <input type=“radio”> A group of radio buttons Entire group has the same name, but different “values” < select> A dropdown list of items The “name” goes on the select tag. Each option will be enclosed in the <option> tags <textarea> A multi line input box

Printing the POST array Sometimes it is helpful when trying to find errors to be able to see the entire POST array that was passed to a form. This can be done with the print_r() command. Print_r prints any array, but to have it print the $_POST array, just add the following command to your PHP: The output will look like: Where each field is in []’s and its value is to the right of the => So in the example above, the input fields we passed were balance, credits, and charges.