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.

Slides:



Advertisements
Similar presentations
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
Advertisements

1 Chapter 5 – Handling HTML Controls in Web Pages spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
Tutorial 6 Working with Web Forms
Form Basics CS Web Data  Most interesting web pages revolve around data  examples: Google, IMDB, Digg, Facebook, YouTube, Rotten Tomatoes  can.
USER INTERACTIONS: FORMS
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.
Using Entities & Creating Forms Jill R. Sommer Institute for Applied Linguistics Kent State University.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
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.),
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Unit 7 – Working with Forms 1. Creating a form 2. Accessing the submitted data 3. Common operations on forms.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
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.
CO1552 Web Application Development HTML Forms. Websites can be made more interactive by providing facilities for users to provide data To get user entered.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Forms A Way for the User to Interact Copyright © newMANIC Inc. All rights reserved.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Website Development with PHP and MySQL Saving Data.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
1 HTML Forms
HTML and FORMS.  A form is an area that can contain form elements.  Form elements are elements that allow the user to enter information (like text fields,
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,
CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.
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. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
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.
Session 8: Working with Form iNET Academy Open Source Web Development.
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.
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 Forms Chapter 9 pp Basic Form Join our list Name:
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
1 HTML forms (cont.)
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
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.
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.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
Creating Forms on a Web Page. 2 Introduction  Forms allow Web developers to collect visitor feedback  Forms create an environment that invites people.
Copyright (c) 2004 Prentice-Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Project 6: Creating XHTML Forms Kelly.
1 HTML forms (cont.)
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
HTML FORM. Form HTML Forms are used to select different kinds of user input. HTML forms are used to pass data to a server. A form can contain input elements.
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.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
How to Write Web Forms By Mimi Opkins.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Validation and Building Small Apps
Introducing Forms.
HTML Forms and User Input
Web Systems Development (CSC-215)
Forms, cont’d.
Presentation transcript:

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 pairs Capturing and using data sent via an HTML form Special formatting considerations

Forms – text box Attributes Type – what type of form object Name – the name of the object Value – whatever is entered into the text field

Forms – radio button Male Female Attributes Type – what type of form object Name – the name of the group Value – the value of each individual radio button

Forms – checkbox Sprinkles Chocolate Sauce Whipped Cream Attributes Type – what type of form object Name – the name of the object Value – whatever is set as the value

Forms – pull down menu (select) Small Medium Large Attributes Name – the name of the pull down menu Value – the value of each of the options within the pull down menu

Forms – text area Attributes Cols – number of columns Rows – number of rows Name – the name of the object Value – whatever is entered into the box. To preload content you enter text in between the start and end tag

Forms – hidden Attributes Type – type of object Name – the name of the object Value – the value of the object – hidden in the browser window

Forms – submit button Attributes Type – type of object Name – the name of the object Value – the caption that appears on the button

Forms – form Attributes Action – the URL of the script that the data will be sent to – this is the page that will display once the submit button is clicked Name – the name of the form Method – the way the data is sent to the script

Input form example All objects must be inside of a form tag All objects inside a form tag have name and value attributes Code Example

Input form example When a user makes a selection or enters data into a form element, the value of the element is automatically set The way the data is sent to the backend script is dependent upon the method attribute set in the form tag

Forms – the get method This is the default method Sends a series of name value pairs appended to the URL It can be book marked Can use the back button to reload it Limited to the amount of data that can be sent

Forms – the post method Sends the name value pairs to the server invisibly – they are not seen by the user Cannot be book marked Page must be reloaded if you use the back button Much larger amounts of data can be sent

PHP $_POST[] & $_GET[] superglobals In order to get at the values stored in the name value pairs you use the $_POST[] and $_GET[] superglobals These superglobals are really arrays. They hold information about all the name value pairs that are sent to the script from the form. The superglobal used is based on the method chosen in the form action

PHP $_POST[] For the form element on the input page: In order to get at the value entered into the myCat form element you would use the following code: echo “I have a cat named ”. $_POST[‘myCat’];

PHP $_GET[] example For the form element on the input page: In order to get at the value entered into the myCat form element you would use the following code: echo “I have a cat named ”. $_GET[‘myCat’];

PHP $_POST[] & $_GET[] variables example It is also possible to assign the value to a variable, and then use it $myCat = $_GET[‘myCat’]; echo “I have a cat named $myCat.” For clarity it is good practice to name your variables the same as the form elements

Escaping quotation marks in strings When sending data to a sever via an input form, PHP automatically escapes single and double quotation marks If you wish to be able to view the text as it was typed you need to unescape the escaped characters

stripslashes( ) The stripslashes() function will remove the escape characters from any string stripslashes(stringOrVariable); You should use stripslashes() on any form value that might contain double or single quotation marks

Server-side forms in PHP Data entered by a user via an HTML form is passed to a backend script in name/value pairs The values associated with each form can be accessed via the $_POST[] or $_GET[] arrays depending on the form method attribute Passed values can be displayed or stored in variables PHP automatically escapes all single and double quotation marks which must be unescaped using stripslashes() to view properly

Forms input – your turn Write the code for the HTML and PHP pages that display the following student marks calculator where CW1 and CW2 are both worth 50% of the overall mark marksResults.php marksForm.php