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.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

LIS651 lecture 0 forms Thomas Krichel
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?
CHAPTER 3 MORE ON FORM HANDLING INCLUDING MULTIPLE FILES WRITING FUNCTIONS.
Slide 1 of 40 PHP Form Handling The PHP superglobals $_GET and $_POST are used to collect form-data. EX: Name: CENG 449 Lecture 11.
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.
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.
CIS101 Introduction to Computing Week 08. Agenda Your questions JavaScript text Resume project HTML Project Six This week online Next class.
Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
PHP Form Processing. Using Forms in PHP  Two steps to process  Display the form  Process the submitted data.
CIS101 Introduction to Computing Week 05. Agenda Your questions CIS101 Survey Introduction to the Internet & HTML Online HTML Resources Using the HTML.
. 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,
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
1 DIG 3134 – Lecture 3 Forms Michael Moshell University of Central Florida Media Software Design.
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 Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Advance web Programming Chapter 3: MySQL Date: 28 April 2014 Advance web Programming Chapter 3: MySQL Date: 28 April 2014 Dr. Mogeeb A. A. Mosleh .
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
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.
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.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Lecture 7 – Form processing (Part 2) SFDV3011 – Advanced Web Development 1.
PHP Hypertext PreProcessor. Documentation Available SAMS books O’Reilly Books.
Slide 1 of 40 PHP Form Handling The PHP superglobals $_GET and $_POST are used to collect form-data. EX: Name: CENG 449 Lecture 11.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
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.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
HTML Form and PHP IST Review of Previous Class HTML table and PHP array Winner is chosen randomly using rand() function.
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.
PHP Form Introduction Getting User Information Text Input.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
Global Variables - Superglobals Several predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
Part 2 Lecture 9 PHP Superglobals and Form Handling.
CHAPTER 7 Introduction to PHP5 Part II อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
Starting BBEdit or Notepad and Opening the HTML File Start BBEdit or Notepad Select Open from the File Menu Open survey1.htm from the Public Folder.
PART 2 INTRODUCTION TO DYNAMIC WEB CONTENT AND PHP.
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 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.
HTML FORM AND PHP IST 210: Organization of Data IST210 1.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
CIS 228 The Internet 12/6/11 Forms and Validation.
CGS 3066: Web Programming and Design Spring 2016 PHP.
PHP and Form Processing CS3520. Idea We have an HTML form that when user clicks on it in their browser a CGI HTTP request is created by the browser and.
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,
Radoslav Georgiev Telerik Corporation
Simple PHP Web Applications Server Environment
Web Systems & Technologies
Pemrograman WEB I Pertemuan 6.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
PHP Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in.
PHP loeng 2.
Intro to PHP & Variables
Creating Forms on a Web Page
Presentation transcript:

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 need to remember. The Form element takes the method and action attributes. Action specifies where the form is sent when submitted and method specifies the http method to be used to send the form. GET and POST are the two most used http methods. Use GET when the information you are sending is not sensitive because all variables and values are displayed in the address bar. The maximum number of characters that can be sent via GET is One advantage of using GET is that the page can be bookmarked. Use POST when the information you are sending is sensitive. Unlimited number of characters can be sent via post.

The super global $_GET and $_POST are used to collect form data in PHP. $_GET is used when the http method used for the form is GET and $_POST is used when the http method used for the form is POST. Now let’s launch wamp server and open the www directory to do some practicals. Open your php folder and create a pages folder in it. Save a new notepad document in it and give it the name register.php, write the following on the page.

.error {color: #FF0000;} <?php // define variables and set to empty values $firstnameErr = $lastnameErr = $middlenameErr =$ Err = $genderErr =""; $firstname = $lastname =$middlename = $ = $gender = ""; //check if the submit button was clicked if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["firstname"])) { $firstnameErr = "first name is required"; } else { $firstname = test_input($_POST["firstname"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$firstname)) { $firstnameErr = "Only letters and white space allowed"; }

if (empty($_POST["lastname"])) { $lastnameErr = "last name is required"; } else { $lastname = test_input($_POST["lastname"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$lastname)) { $lastnameErr = "Only letters and white space allowed"; } if (empty($_POST["middlename"])) { $middlenameErr = "middle name is required"; } else { $middlename = test_input($_POST["middlename"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$middlename)) { $middlenameErr = "Only letters and white space allowed"; }

if (empty($_POST[" "])) { $ Err = " is required"; } else { $ = test_input($_POST[" "]); // check if address is well-formed if (!filter_var($ , FILTER_VALIDATE_ )) { $ Err = "Invalid format"; } if (empty($_POST["sex"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["sex"]); }

function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> Registration form * required field. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> First Name: "> * Last Name: "> * Middle Name: "> * "> *

Gender: value="female">Female value="male">Male * <?php echo " Below is the information you entered "; echo "first name: ".$firstname; echo " "; echo "last name: ".$lastname; echo " "; echo "middle name: ".$middlename; echo " "; echo "your address is: ".$ ; echo " "; echo "you are a: ".$gender; ?>

Explanation of the registration form. Because our form method is post, we use $_POST super global to access the form. The validation rule for the form is that all fields must be filled, the must be valid and gender must be selected. The super global $_SERVER[“PHP_SELF”] returns the file name of the currently executing script. The form data is submitted to itself instead of a new page. this way the user will get error messages on the same page as the form. This super global can be exploited. To prevent cross site scripting attacks, the htmlspecialchars() function is used to convert special characters to html entities.

htmlspecialchars(): this function converts special characters to HTML entities and prevents attackers from exploiting the code by injecting scripts in forms. (prevents XSS attacks). trim(): the trim function removes extra spaces, tabs and newline from the user input data. stripslashes(): this function removes backslashes from user input. The function test_input that we have written uses the functions mentioned above to perform its functions on the input.