PHP Form Processing. Using Forms in PHP  Two steps to process  Display the form  Process the submitted data.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
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.
Tutorial 6 Creating a Web Form
PHP Workshop ‹#› Forms (Getting data from users).
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Video, audio, embed, iframe, HTML Form
Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
JavaScript Forms Form Validation Cookies CGI Programs.
Apache Tomcat Server – installation & use Server-side language-- use Java Server Pages Contrast Client-side languages HTML Forms Servers & Server-side.
Tutorial 14 Working with Forms and Regular Expressions.
Using Entities & Creating Forms Jill R. Sommer Institute for Applied Linguistics Kent State University.
PHP Form Processing. Using Forms in PHP  Two steps to process  Display the form  Process the submitted data.
Simple PHP application. A simple application We are going to develop a simple PHP application with a Web interface. The user enters two numbers and the.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
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.
Uploading Files. Why? By giving a user the option to upload a file you are creating an interactive page You can enable users have a greater web experience.
. If the PHP server is an server or is aware of which server is the server, then one can write code that s information. –For example,
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Stupid Browser Tricks with PHP and JavaScript By Chris Winikka.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
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.
Unit 7 – Working with Forms 1. Creating a form 2. Accessing the submitted data 3. Common operations on forms.
Web Forms with PHP COEN 351. Displaying and processing a simple form if( array_key_exists(‘my name’,$_POST)){ print “Hello, “.$_POST[‘my_name’]; } else.
ITM © Port, Kazman1 ITM 352 HTML Forms, Basic Form Processing.
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.
Chapter 4 Handling User Input PHP Programming with MySQL 2nd Edition
JavaScript Form Validation
PHP : Hypertext Preprocessor
1 Chapter 6 – Creating Web Forms and Validating User Input spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
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.
(c) Manzur Ashraf, Short course, KFUPM PHP & MySQL 1 Basic PHP Class 2.
HTML Forms What is a form.
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.
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
Lecture 7 – Form processing (Part 2) SFDV3011 – Advanced Web Development 1.
Tutorial 14 Working with Forms and Regular Expressions.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Homework for October 2011 Nikolay Kostov Telerik Corporation
Week 7. Lecture 3 PHP Forms. PHP forms In part 2 of this course, we discussed html forms, php form is similar. Lets do a quick recap of the things we.
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
BBK P1 Module2010/11 : [‹#›] Forms (Getting data from users)
Website Development with PHP and MySQL Saving Data.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
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,
More on Variables Some related techniques. Header() function void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) header()
JavaScript and PHP Validation and Error Handling CHAPTER 17.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
Part 2 Lecture 9 PHP Superglobals and Form Handling.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
HTML5 Forms Forms are used to capture user input …
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.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Creating Forms on a Web Page. 2 Introduction  Forms allow Web developers to collect visitor feedback  Forms create an environment that invites people.
CITA 310 Section 4 Apache Configuration (Selected Topics from Textbook Chapter 6)
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
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.
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,
Radoslav Georgiev Telerik Corporation
Web Programming– UFCFB Lecture 17
Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314
JavaScript Form Validation
Today’s Objectives Week 12 Announcements ASP.NET
Presentation transcript:

PHP Form Processing

Using Forms in PHP  Two steps to process  Display the form  Process the submitted data

Program Structure if (array_key_exists( 'elementName', $_POST)) // process submitted data else // display the form

Using Forms in PHP  The form can use either the POST method or the GET method  The action for the form is a php file (either the one that displays the form or a different one)

Post or Get?  If the GET method is used, data from the form is included at the end of the URL of the php file that will process the data  If the post method is used, form data is sent as input to the program  In either case, the data will be stored in the appropriate autoglobal array

Server variables $_POST is an array containing post data $_GET contains data if the GET method is used $_SERVER is an array which makes information about the server and the request available to the program  PHP_SELF, QUERY_STRING, PATH_INFO, SERVER_NAME, DOCUMENT_ROOT, REMOTE_ADDR, REMOTE_HOST, HTTP_REFERER, HTTP_USER_AGENT

Data Validation  PHP can be used to validate form data  The form data is sent to the server to be validated

Program Structure if (array_key_exists( 'elementName', $_POST)) if (validateForm()) // process data else // redisplay form else // display the form

Validation techniques  Check the length ( strlen ) of string to make sure something was entered  use trim() first to remove leading and trailing space  Check numeric data by comparing the original with converted value strval( intval( $input)) strval( floatval( $input))  Do any necessary range checking

Validating Addresses Use a regular expression to check for valid format for addresses $pattern = if (! preg_match($pattern,$_POST[' '])) { $errors[] = 'Please enter a valid address'; }

Sanitizing Input  What happens if a user types HTML code (or JavaScript code) into a textarea?  PHP provides two functions for cleaning up input  strip_tags() removes all HTML tags and leaves the content  htmlentities() converts HTML special characters to corresponding entity

Displaying Default values if ($_POST['_submit_check']) { $defaults = $_POST; } else { $defaults = array( 'delivery' => 'yes', 'size' => 'medium', 'main_dish' => array('taro','tripe'), 'sweet' => 'cake'); }

Sources  Learning PHP 5 by David Sklar  PHP home page 