PHP Forms. I. Using PHP with HTML Forms A very common application of PHP is to have an HTML form gather information from a website's visitor and then.

Slides:



Advertisements
Similar presentations
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
Advertisements

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.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
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.
Servlets and a little bit of Web Services Russell Beale.
HTML Form Processing Learning Web Design – Chapter 9, pp Squirrel Book – Chapter 11, pp
Outline Overview about Web Page HTML Form Creation FORM Input INPUT control types GET & POST PHP File Upload PHP Include Files Headers Cookie Sessions.
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
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.
PHP – Get & Post; Functions; and Arrays IS6116 – 07 th February 2011.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
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.
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.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
INTERNET APPLICATION DEVELOPMENT For More visit:
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Lecture 7 – Form processing (Part 2) SFDV3011 – Advanced Web Development 1.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Server-side Scripting Powering the webs favourite services.
Python CGI programming
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Nic Shulver, Introduction to Sessions in PHP Sessions What is a session? Example Software Software Organisation The login HTML.
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.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
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,
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
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.
Global Variables - Superglobals Several predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope.
Introduction to PHP.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
1 HTML forms (cont.)
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.
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
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
1 HTML forms (cont.)
1 CS428 Web Engineering Lecture 22 Building Dynamic Web pages (PHP - V)
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.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
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.
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.
PHP – Hypertext Preprocessor.
Simple PHP Web Applications Server Environment
Tonga Institute of Higher Education IT 141: Information Systems
Session 2 Basics of PHP.
CHAPTER 5 SERVER SIDE SCRIPTING
How to Write Web Forms By Mimi Opkins.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
8th Semester, Batch 2008 Department of Computer Science SSUET.
PHP FORM HANDLING Post Method
Intro to PHP & Variables
Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314
Tonga Institute of Higher Education IT 141: Information Systems
Web Systems Development (CSC-215)
Tonga Institute of Higher Education IT 141: Information Systems
HTTP GET vs POST SE-2840 Dr. Mark L. Hornick.
Lecture 5: Functions and Parameters
PHP Forms and Databases.
PHP-II.
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Presentation transcript:

PHP Forms

I. Using PHP with HTML Forms A very common application of PHP is to have an HTML form gather information from a website's visitor and then use PHP to do process that information. In this lesson we will simulate a small business's website that is implementing a very simple order form. Imagine we are an art supply store that sells brushes, paint, and erasers. To gather order information from our prospective customers we will have to make a page with an HTML form to gather the customer's order. Note: This is an oversimplified example to educate you how to use PHP to process HTML form information. This example is not intended nor advised to be used on a real business website.

The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts. We first create an HTML form that will let our customer choose what they would like to purchase. This file should be saved as "order.html" Paint Brushes Erasers Quantity:

A form can have the method set as post or get. When using a form with method = "post" you can use $_POST to access the form values. And when the form is using method = "get" you can use $_GET to access the values. The $_REQUEST super global can be used to access form values with method="post" and method="get" but it is recommended to use $_POST or $_GET instead so you will know from what method did the values come from. Next we must alter our HTML form to specify the PHP page we wish to send this information to. Also, we set the method to "post".

order.html Code adding post : Jamuna Art Supply Order Form Paint Brushes Erasers Quantity: Now that our "order.html" is complete, let us continue on and create the "process.php" file which will process the HTML form information.

We want to get the "item" and "quantity" inputs that we have specified in our HTML form. The proper way to get this information would be to create two new variables, $item and $quantity and set them equal to the values that have been "posted". The name of this file is "process.php". <?php $quantity = $_POST['quantity']; $item = $_POST['item']; echo "You ordered ". $quantity. " ". $item. ". "; echo "Thank you for ordering from Jamuna Art Supplies!"; ?>

1. The GET method The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character.  The GET method produces a long string that appears in your server logs, in the browser's Location: box.  The GET method is restricted to send up to 1024 characters only.  Never use GET method if you have password or other sensitive information to be sent to the server.  GET can't be used to send binary data, like images or word documents, to the server. csc

 The data sent by GET method can be accessed using QUERY_STRING environment variable.  The PHP provides $_GET associative array to access all the sent information using GET method. As we mentioned before, the alternative to the post method is get. If we were to change our HTML form to the get method, it would look like this:...

Example : Get_method.php Using Method Get " method="get"> Using Get method Name: Age: <?php if($_GET['name'] !="" || $_GET['age']!="" ) { echo "Welcome ". $_GET['name']. " "; echo "You are ". $_GET['age']. " years old."; exit(); } ?>

 There are a few disadvantages to passing variables through a URL: Everyone can see the values of the variables, so passing sensitive information isn’t really very secure using this method. The user can change the variable value in the URL, leaving your site potentially open to showing something you’d rather not show. A user might also pull up inaccurate or old information using a saved URL with older variables embedded in it.

When to use method="get"? When using method="get" in HTML forms, all variable names and values are displayed in the URL. Note: This method should not be used when sending passwords or other sensitive information! However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases. Note: The get method is not suitable for very large variable values. It should not be used with values exceeding 2000 characters.

2. The POST Method The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING.  The POST method does not have any restriction on data size to be sent.  The POST method can be used to send ASCII as well as binary data.  The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure.  The PHP provides $_POST associative array to access all the sent information using GET method.

Example : Post_method.php <?php if( $_POST["name"] || $_POST["age"] ) { echo "Welcome ". $_POST['name']. " "; echo "You are ". $_POST['age']. " years old."; exit(); } ?> " method="POST"> Name: Age:

When to use method="post"? Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. However, because the variables are not displayed in the URL, it is not possible to bookmark the page.

3. The $_REQUEST variable The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE. We will discuss $_COOKIE variable when we will explain about cookies. The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods. Example : Welcome ! You are years old.

Example : request.php <?php if( $_REQUEST["name"] || $_REQUEST["age"] ) { echo "Welcome ". $_REQUEST['name']. " "; echo "You are ". $_REQUEST['age']. " years old."; exit(); } ?> " method="POST"> Name: Age:

" method="post">

THE END