Mr. Justin “JET” Turner CSCI 3000 – Fall 2016 Section DA MW 4:05-5:20

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
PHP File Upload ISYS 475.
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.
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
Python and Web Programming
FILE UPLOADS CHAPTER 11. THE BASIC PROCESS 1.The HTML form displays the control to locate and upload a file 2.Upon form submission, the server first stores.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Principles of Web Design 6 th Edition Chapter 11 – Web Forms.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
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.
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
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.
Lesson 13: Building Web Forms Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver CS6.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
D2L Notes Be sure to submit your link in the dropbox provided on D2L You can just upload an empty text file if a file upload is required Do not use D2L.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
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,
Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
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.
Advanced Web 2012 Lecture 6 Sean Costain Files Sean Costain 2012 Php allows for the : Creation Reading Appending Deleting Uploading And Closing.
CST336, Spring 2015 Week 8: PHP File Upload. PHP provides specific functions to handle binary data such as uploading a file into the server, storing it.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
+ 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.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Advanced HTML Tags:.
How to Write Web Forms By Mimi Opkins.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Using the HTML and CSS Validation Services
>> PHP: File Uploads
Play Framework: Introduction
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
PHP Training at GoLogica in Bangalore
PHP / MySQL Introduction
Validation and Building Small Apps
Cookies BIS1523 – Lecture 23.
HTML Forms and User Input
MVC Framework, in general.
Web Systems Development (CSC-215)
Client side & Server side scripting
Building Web Applications
PHP and Forms.
Web Development Using ASP .NET
Client-Server Model: Requesting a Web Page
PHP.
Web Application Development Using PHP
Presentation transcript:

Mr. Justin “JET” Turner CSCI 3000 – Fall 2016 Section DA MW 4:05-5:20 PHP Mr. Justin “JET” Turner CSCI 3000 – Fall 2016 Section DA MW 4:05-5:20

Form Handling When creating an HTML form, there are several attributes we can set that determine how we will handle the data from the form when it is submitted Action Default is same page Method Default is “GET”, often changed to “POST” GET shows up in the URL, POST does not Enctype Set to “multipart/form-data” if you have a file upload

Form Handling On the PHP side, the data submitted by the form is stored in predefined arrays: GET : $_GET[] POST: $_POST[] Both: $_REQUEST[] You should only use $_REQUEST if you need your code to accept GET or POST data Normally we chose one method or the other for any given form submission

Form Handling Once a form is submitted, we need to have PHP validate the data in each field to confirm we are getting what we expect We often use strlen() and isset() with other basic logic to ensure each field has the data we expect If we are handling the form submission on the same page as the form, we also want to check and see if the form was even submitted before trying to validate if(isset($_POST[‘submitButtonName’]))

Form Handling Let’s set up a simple form and do some basic validation tasks

File Handling There are two types of File Handling I want to discuss today Files uploaded via a form submission Working with files on the server

File Uploads As discussed earlier, we need to set the enctype of the form so it will accept the file uploads When the form is submitted, the server takes the file and stores it in a temporary location PHP then builds another array variable with information about the file uploaded and the current temporary location/filename called $_FILES[] name, type, tmp_name, error, size

File Uploads The primary tasks we need to perform for a file upload are: Set form to accept files Validate that the file is of an allowed type/size/etc Move the file from the temp location to a permanent location During this move, we should generally set a new unique name (often we use a timestamp)

File Uploads Validating a file type is usually done based on the file extension, and not based on the “type” array element PHP provides a function for this: pathinfo(“filename.ext”, PATHINFO_EXTENSION) Generally we want to chose a small set of file types to allow, as opposed to choosing a few not to allow This is a security practice to prevent a user from uploading a malicious script/page of some type to your server

File Uploads When moving the file out of the temporary directory, we need to have a directory coded in for where it will go, and a way to ensure the filename is unique (often adding a timestamp) uploads_directory/filename_unixtimestamp.ext Then we can use a PHP function to get the file moved to where it belongs move_uploaded_file($tempName, $newPathAndName)

File Uploads Depending on what we are having the user upload, sometimes we will want the upload directory to not be visible from the web, so we create the folder at the same level as httpdocs Other times, we want to make the files accessible (often this is the case with images), so we will put the upload folder somewhere inside of httpdocs

File Handling Now that we have a file on the server, we want to access it for use on our site One simple task we can do is list all the files in a given directory scandir() is_dir()

File Handling Another task we sometimes need to do is force a file to be downloaded, instead of being opened in the browser This process can also hide the true path to the file, or access files that are not normally accessible by the browser http://php.net/manual/en/function.readfile.php

File Handling The readfile() command can also be used to store the contents of a file into a variable for processing by PHP (maybe reading a text file for instance) We can also use encryption and decryption functions to store the files on the server in an encrypted way, and only decrypt them when sending them as a download to an authorized user

Includes Sometimes the code for a site can get very bulky, or you end up with several functions you want to use on different pages To handle this, we can create a PHP file that isn’t designed to render as web content, but is more of a library of functions we want to be able to use include / include_once require / require_once

Includes It is very common to have these pages of functions, and often some additional constants we need to set up We can help secure these kinds of pages we don’t want the user to browse to by using: get_included_files() Which returns an array of all the pages being included We can then use this to tell if we should redirect the user, or allow the page to be included

Classes / Object Oriented Sometimes it can be helpful to build our PHP with classes to be Object Oriented The basic structure is very similar to how you might build a class using Java class MyClass { }

Classes / Object Oriented To create an object of the class, we use the ‘new’ keyword $obj = new MyClass; To access instance data or class methods, we use an arrow $obj->data1; $obj->afunction();

Classes / Object Oriented Some functions we will want to implement in our classes: public function __construct() public function __toString() We can also build classes from others (parent/child, inheritance) class MyOtherClass extends MyClass public function __construct() { parent::__construct();//calls parent constructor }

Classes / Object Oriented public/private/protected work the same as in Java public is accessible from the created object private is only accessible inside the given object protected is only accessible inside the given object and inside child objects

Classes / Object Oriented When we get into the Model, View, Controller(MVC) framework in a couple of weeks, we will be using a PHP framework that is OOP, so it is important you have a basic understanding of classes and how to use them in PHP

Lab 3 - PHP Due: Oct 5th Create a PHP page with a simple web form Include at least: Two text fields (<input type=‘text’>) One drop down (<select>) One radio button group with at least two radio buttons (<input type=‘radio’> //same name attribute will cause them to group together) A submit button

Lab 3 - PHP Set up PHP code to validate that all fields had values entered Create styled error messages if fields were not completed (for example, red text saying which field was not completed) Output the values entered on the page

Next Time MySQL Basic DB background How to create a DB in GoDaddy How to create tables How to query data in tables