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

Cross-Site Scripting Issues and Defenses Ed Skoudis Predictive Systems © 2002, Predictive Systems.
CHAPTER 3 MORE ON FORM HANDLING INCLUDING MULTIPLE FILES WRITING FUNCTIONS.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
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).
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
JavaScript Forms Form Validation Cookies CGI Programs.
PHP Form Processing. Using Forms in PHP  Two steps to process  Display the form  Process the submitted data.
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.
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.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
. 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.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
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.
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.
(c) Manzur Ashraf, Short course, KFUPM PHP & MySQL 1 Basic PHP Class 2.
CP3024 Lecture 3 Server Side Facilities. Lecture contents  Server side includes  Common gateway interface (CGI)  PHP Hypertext Preprocessor (PHP) pages.
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.
Web111a_chapt06.ppt HTML: Section 6 Forms HTML tags: define data input and/or output Define the Input and/or Output on the web page Do not process the.
Tutorial 14 Working with Forms and Regular Expressions.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
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.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
FUNCTIONS AND STORED PROCEDURES & FUNCTIONS AND PROTECTING A DB AND PHP (Chapters 9, 15, 18)
Attacking Applications: SQL Injection & Buffer Overflows.
Using Client-Side Scripts to Enhance Web Applications 1.
 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.
More on Variables Some related techniques. Header() function void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) header()
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
HTLM Forms CS3505. Form Handling in Browser html User Files out form WEbBROWSErWEbBROWSEr User read response submit Get URL?input html Get file html script.
Form Handling IDIA 618 Fall 2014 Bridget M. Blodgett.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
 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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Introduction to CGI PROG. CGI stands for Common Gateway Interface. CGI is a standard programming interface to Web servers that gives us a way to make.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Tutorial 6 Creating a Web Form
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 13 Scott Marino.
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
DBW - PHP DBW2017.
Web Programming– UFCFB Lecture 17
Dr. John P. Abraham Professor UTRGV eCommerce CSCI 6314
PHP: Security issues FdSc Module 109 Server side scripting and
JavaScript Form Validation
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'); }

Running Shell Commands  PHP provides the shell_exec() function for running an external program from the php program $filelist = shell_exec( 'ls');  If you are passing form input on to another program, use escapeshellargs() to clean it up first

Extensions  The mycrypt extension to PHP provides a number of standard encryption algorithms  The Perl and Java extensions allow you to execute code written in those languages from your PHP program  PEAR is an extension that is useful for applications that use databases  more next time

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