Advance Database Management Systems Lab no. 5 PHP Web Pages.

Slides:



Advertisements
Similar presentations
HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
Advertisements

WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
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.
Lecture 14 HTML Forms CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
Python and Web Programming
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.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
IS1500: Introduction to Web Development
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.
ITM © Port, Kazman1 ITM 352 HTML Forms, Basic Form Processing.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
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:
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.
Forms and Form Controls Chapter What is a Form?
Lesson 13: Building Web Forms Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver CS6.
Lecture 7 – Form processing (Part 2) SFDV3011 – Advanced Web Development 1.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Internet / Intranet CIS-536 Class 7. 2 HTML Forms A Method to Allow Users to Pass Information to a CGI Script Forms Allow Information to Be Entered Via:
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Website Development with PHP and MySQL Saving Data.
HTML Forms.
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 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
CSC 2720 Building Web Applications Server-side Scripting with PHP.
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.
1 Review of Form Elements. 2 The tag Used in between tags.  Form elements(text control, buttons, etc.. ) goes here. OR  Form elements(text control,
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
HTML Forms a form is a container for input elements on a web page input elements contain data that is sent to the web server for processing.
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.
SYST Web Technologies SYST Web Technologies XHTML Forms.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Web Page Design Forms! Website Design. Objectives What forms can do The Attributes of the form tag Using Textboxes Textareas Checkboxes Radio buttons.
+ 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.
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.
Netprog CGI and Forms1 CGI and Forms A detailed look at HTML forms.
HTML Forms.
Week 10: HTML Forms HNDIT11062 – Web Development.
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.
1 HTML Forms
Copyright (c) 2004 Prentice-Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Project 6: Creating XHTML Forms Kelly.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
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.
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
How to Write Web Forms By Mimi Opkins.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
CS3220 Web and Internet Programming HTML Tables and Forms
Introducing Forms.
CS3220 Web and Internet Programming HTML Tables and Forms
Creating Forms on a Web Page
PHP-II.
Presentation transcript:

Advance Database Management Systems Lab no. 5 PHP Web Pages

Introduction So far we have considered static web pages. We used PHP scripts to write simple programs with (built-in) capability to perform computation Now, we’d like to build smarter pages which Respond to user’s actions Retrieve dynamic information Support conditional behavior

Problem: Handling user input We still don’t have a way to get input from the user. Note:PHP does not have its web controls as ASP has.

Getting User Input There can be two ways of getting Input data from user URL Paremeters and $_GET array Web Forms (HTML CONTROLS)

URL Parameters PHP has the capability to pull parameters out of the URL query string Parameters can be passed as text after the file name, e.g., name=john & age=2 Parameter names and values can be accessed as variables using special array named $_GET

URL Parameters Example Browser retrieves the URL: host/test.php?name=john &age=2 in test.php <?php echo $_GET[“name”]; // displays john echo $_GET[“age”]; // displays 2 ?>

Web Forms (HTML Controls) We need a more elegant way of passing parameters to PHP pages HTML forms can be used to accept input from users which contain a set of input tags Text boxes, checkboxes, etc. Form pages can submit data to a PHP page Pass input values in query string

Creating web forms Form tag controls what is done with data action: Page to submit results to method: How to submit data, name: Used to refer to the form

Form Actions The form’s ACTION is the name of the PHP script (points to PHP page) When the user submits the form the web server executes the PHP script in results.php file

Form submission methods HTTP supports two methods for submitting form data GET Parameters are passed in URL string Parameters visible to user in browser window Easy to debug POST Parameters included in body of HTTP request Not visible to user Can handle larger data items

$_GET Function The built-in $_GET function is used to collect values from a form sent with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send (max. 100 characters).

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 large variable values; the value cannot exceed 100 characters.

Form inputs Allow users to input data Generally have a name and a value Map to parameters when form is posted Text box Textarea (larger text box) Checkbox Radio button Menu Submit button

HTML Controls RECAP

Text input/Text Box One-line text input name: input name value: default value size: length (in characters) maxlength: Maximum number of characters to accept

Text area Larger, multiline text box Default text goes inside tags Name: input name Cols: width (in characters) Rows: number of rows

Checkbox Checkbox, allows for boolean choices Name: input name Value: value if checked (name=value) Checked: if included, box is checked by default

Select (pulldown or menu) Allows user to choose item from a dropdown menu I prefer coffee I prefer tea Will submit variable “beverage” with value “coffee” or “tea”

Radio button Presents multiple options, user chooses one Each item in a group has same name, different value Only one button can be checked by default Value of parameter fruit will be apple, papaya,mango

Hidden field Sometimes we want to pass data to forms without user’s input User’s password, current time Won’t be shown to user Will pass parameter “key=hello” to form

Submit button When clicked, submits form data to target Value: Label of submit button

Labeling form elements The most common way to add labels is simply to place text beside the form input Add me to mailing list: <input type=”checkbox" name=”addtolist" value=”true" checked=“checked” /> Save password: <input type=”checkbox" name=”savepw” value=”true" checked=“checked” />

Other PHP server variables $_POST Like $_GET, but for POST requests $_REQUEST Searches both GET and POST for parameters $_SERVER Stores additional information from server User’s IP address, host URL, etc

$_POST The built-in $_POST function is used to collect values from a form sent with 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. Note: However, there is an 8 Mb max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file).

Name: Age: When the user clicks the "Submit" URL will change to welcome.php. in "welcome.php" file,we can now use the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array): Welcome ! You are years old. $_POST Example

Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. When to use method “POST”?

$_REQUEST The PHP built-in $_REQUEST function contains the contents of both $_GET, $_POST, and $_COOKIE. The $_REQUEST function can be used to collect form data sent with both the GET and POST methods. Example Welcome ! You are years old. $_REQUEST

$_SERVER When the variable has been assigned from the server $_SERVER

Example Test page Form demo <form action="results.php" method="get" name="hello"> Enter message: <input type="text" name="message" value="Hi“ />

Accessing form data //results.php <?php $user = $_GET[“username”]; echo “You entered “. $user; ?>

Form validation When we process forms, we can’t be sure that the user included correct information May have left fields blank May have put in improper information Never Trust User Input! We may want to validate the form input before using it PHP provides a number of functions to help us validate form input isset() is variable null? is_numeric() is variable a numeric type? is_string() is variable a string?

Validation example <?php // multiply a number by two // get parameter “num” from url string $num = $_GET[“num”]; // is $num a number? if not, throw an error if (!is_numeric($num)) { echo “Error!”; } else { echo $num*2; } ?>

Including libraries Place PHP file in same directory or subdirectory Simpler than Java, no packages or namespaces Essentially pastes included code into file

PHP Include File Server Side Includes (SSI) You can insert the content of one PHP file into another PHP file before the server executes it using two types of functions. include() generates a warning in case errors in included file, but the script will continue execution require() generates a fatal error, and the script will stop These two functions are used to create functions, headers, footers, or elements that will be reused on multiple pages.

Server side includes saves a lot of work. This means that you can create a standard header, footer, or menu file for all your web pages. When the header needs to be updated, you can only update the include file, or when you add a new page to your site, you can simply change the menu file (instead of updating the links on all your web pages).

Include example in math.php: <?php function mult($n1,$n2) { return $n1*$n2; } ?> in index.php: <?php include(“math.php”); echo mult(15,5); ?>