_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

CHAPTER 3 MORE ON FORM HANDLING INCLUDING MULTIPLE FILES WRITING FUNCTIONS.
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.
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.
Server-Side vs. Client-Side Scripting Languages
JavaScript Forms Form Validation Cookies CGI Programs.
Python and Web Programming
Session Management A290/A590, Fall /25/2014.
Using Entities & Creating Forms Jill R. Sommer Institute for Applied Linguistics Kent State University.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Chapter 4 Handling User Input PHP Programming with MySQL 2nd Edition
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.
INTERNET APPLICATION DEVELOPMENT For More visit:
Lecture 7 – Form processing (Part 2) SFDV3011 – Advanced Web Development 1.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
JavaScript, Fourth Edition
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
PHP meets MySQL.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
Website Development with PHP and MySQL Saving Data.
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.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
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,
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.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
Chapter 4: Working with ASP.NET Server Controls OUTLINE  What ASP.NET Server Controls are  How the ASP.NET run time processes the server controls on.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of.
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.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Netprog CGI and Forms1 CGI and Forms A detailed look at HTML forms.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
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.
Basic ActionScript and PHP Cis 126. Getting Started set up a basic folder structure so we can keep our files organized. Mirror this structure on your.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
PHP Form Processing * referenced from
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
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,
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Simple PHP Web Applications Server Environment
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Validation and Building Small Apps
Introducing Forms.
Client side & Server side scripting
Session Tracking Techniques
PHP-II.
Presentation transcript:

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the book authors, 2002 PHP Bible Chapter 7: Passing Info Between Pages

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition2  Wiley and the book authors, 2002 Summary Why PHP is like a rolling stone GET arguments A better use for GET-style URLs POST arguments Formatting form variables PHP super-arrays Extended example: an exercise calculator

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition3  Wiley and the book authors, 2002 HTTP is "Stateless" The most important thing to recall about the way the Web works is that the HTTP protocol itself is stateless. Consequently, each HTTP request is independent of all of the others, knows nothing substantive about the identity of the client, and has no memory. Each request spawns a discrete process, which goes about its humble but worthy task of serving one single solitary file and then is automatically killed off. Someone can enter information into a form on one page, but unless you employ some extra means to pass the information to another page or program, the variable will simply vanish into the ether as soon as they move to another page In chapter 27 we'll discuss ways of saving variables across multiple page views using sessions and cookies. ASP developers might comment at this point that ASP session variables are "magic", but Microsoft just uses cookies to store session variables, opening the door to all kinds of potential problems.

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition4  Wiley and the book authors, 2002 GET Arguments The GET method passes arguments from one page to the next as part of the URI (Uniform Resource Indicator). When used for form handling, GET appends the indicated variable name(s) and value(s) to the URL designated in the ACTION attribute of the FORM tag with a question-mark separator and submits the hole thing to the processing agent (the web server) In the browser URI, following the URL is:  A question mark denoting the beginning of the GET string  A variable name followed by an equals sign followed by the matching value  An ampersand (&) and the next NAME-VALUE pair…

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition5  Wiley and the book authors, 2002 GET Arguments - example The following example shows how to use PHP to retrieve data sent via the GET method: Hi there <?PHP if (isset($_GET['first_name']) && isset($_GET['last_name'])) print ('Hello '.$_GET['first_name'].' '.$_GET['last_name']); else print ('I don\'t know who you are'); ?>

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition6  Wiley and the book authors, 2002 GET Arguments (cont.) The GET method of form handling offers one big advantage over the POST method: It constructs an actual new and differentiable URL query string which can be bookmarked, etc. The disadvantages of GET for most types of form handling are so substantial that the original HTML 4.0 specification deprecated its use. Its faults include:  GET is not suitable for logins since the username and password are fully visible onscreen as well as potentially stored in the client browser's memory as a visited page  Every GET submission is recorded in the Web server log, including the data set  Because the GET method assigns data to a server environment variable, the length of the URL is limited. GET is still useful for implementing search queries, but not much else

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition7  Wiley and the book authors, 2002 A better use for GET-style URLs Although GET was deprecated for handling forms, it's quite useful for site navigation on large sites utilizing templates for the individual pages  Instead of having pages named suspension_design.html, powertrain_design.html, engine_design.html, etc. which all have a similar look & design, you could have a single PHP script which brings in the content for the individual pages based upon the values of the GET variables  Use a single PHP script which sets up the navigation, logos, styles, etc. and the included pages include the content & pictures, etc.  Which included page is loaded is dependent on the arguments passed in via the GET method You could also access your content from data contained in databases instead of included text files

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition8  Wiley and the book authors, 2002 POST Arguments POST is the preferred method of form submission When utilizing the POST method, no visible changes to the URL are made POST has advantages over GET because:  It is more secure since user-entered information is never visible in the URL, browser history, or server logs  There is a much larger limit on the amount of data that can be passed POST is less advantageous than GET when:  The user wants to be able to bookmark the resultant page  The user is behind certain types of firewalls which strip the form data as a security measure (very rare)

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition9  Wiley and the book authors, 2002 Formatting form variables PHP automatically, but invisibly, assigns the variables for you on the page receiving the form output when you submit a data set using the GET or POST method (unlike other languages which require you to perform this assignment yourself on each page) Because of this automatic variable assignment, you need to use a good NAME attribute for each INPUT, SELECT, or TEXTAREA tag in your HTML form. NAME attributes are not strictly necessary in HTML – your form will render fine without them – but the data will be of little use because the HTML form field NAME attribute will be the variable name or index in the form handler

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition10  Wiley and the book authors, 2002 Formatting form variables (cont.) In the form fields:  The text field named will cause the creation of an index in the $_POST array called ' ' ($_POST[' ']) with the value of what the user had typed into that field. The submit button will likewise cause the creation of an index in the $_POST array called 'submit'. Because this is being sent to a PHP script, the names you use in the HTML form are case-sensitive and should not begin with numbers (use the standard PHP conventions for creating your variable names) If you want data to be pre-filled on the HTML form, use the VALUE attribute (or CHECKED attribute for checkboxes and radio buttons) which is useful if you're using the form to edit information in a database or allowing the user to correct problems with a previously submitted form

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition11  Wiley and the book authors, 2002 Consolidating forms and form handlers It is often handy to consolidate the HTML form and the form handler (the PHP script that the form gets submitted to) into a single script This makes it easier to display error messages and prefilled form fields and achieving better control over your variable namespace (you won't have to remember what the variable was called in your HTML form in your form processing script)  This could be useful, for example, if you are creating a login form that redisplays with an error message if the login is unsuccessful You won't even have to remember the name of the script to submit your form to if you use a tag construct similar to this: " METHOD="POST">

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition12  Wiley and the book authors, 2002 Consolidating forms and form handlers (cont.) When consolidating forms with the form processing scripts, generally the form-handling code should come before the form display  This will give you the opportunity to set variables and make choices before you can decide what to show the user If you want to check and see whether you're displaying a form for the first time or whether it's already been submitted at least once  Use the submit button by checking to see if $_POST['submit'] has been set  Set a hidden variable in the form and check to see whether or not it has a value (the first time the form is viewed, it will not have been set)  You could also use the hidden variable as a counter to see how many times the user has submitted this form

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition13  Wiley and the book authors, 2002 Using array variables with forms In most forms, each input field will create a single index into the $_POST or $_GET array PHP also allows you to post an array-type variable In the form HTML, you can create an array variable by putting an opening and closing square bracket after it (which may also include an index into that array) It's also important to note that if you use the MULTIPLE attribute in a SELECT HTML tag, the receiving form processing script will receive an array of all of the items that were selected from the list (even if only 1 or no items were selected)

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition14  Wiley and the book authors, 2002 PHP Superglobal arrays PHP starting with version 4 implemented what are called superglobal arrays These arrays are global to every function in your PHP script (unlike other variables which must be passed into the function as arguments or declared global inside the function body) They contain information about the operating environment of your PHP script  $_GET: Contains variables submitted via the GET method  $_POST: Contains variables submitted via the POST method  $_COOKIE: Contains variables stored in cookies  $_SESSION: Contains variables stored in sessions  $_SERVER: Contains miscellaneous information about the server environment including headers, paths, and script locations  $_ENV: Contains OS environment information