BBK P1 Module2010/11 : [‹#›] Forms (Getting data from users)

Slides:



Advertisements
Similar presentations
PHP Workshop ‹#› Forms (Getting data from users).
Advertisements

Supplement Creating Forms. Objectives Show how forms are used How to create the Form element HTML elements used for creating input fields.
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.
Tutorial 6 Working with Web Forms
Forms Review. 2 Using Forms tag  Contains the form elements on a web page  Container tag tag  Configures a variety of form elements including text.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
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.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
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 Security.
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.
Programming Methodology and Web Rapid Prototyping (Session 3) TC101, 5 Sessions course, Conducted by Solvith Solvith PHP Course-
1 HTML Forms. 22 HTML forms provide a way for a user to send information back to the web server. Originally the user input was processed on the server.
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.
INTRODUCTORY Tutorial 8 Creating Forms. XP New Perspectives on Blended HTML, XHTML, and CSS2 Objectives Create an HTML form Create fields for text Create.
HTML Forms.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
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.
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,
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.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
IS2802 Introduction to Multimedia Applications for Business Lecture 5: JavaScript, form validation and browser detection Rob Gleasure
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,
Session 8: Working with Form iNET Academy Open Source Web Development.
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.
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.
+ 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.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
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.
Copyright (c) 2004 Prentice-Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Project 6: Creating XHTML Forms Kelly.
Web Forms. Web Forms: A form allows our web visitors to submit information to us. Some examples uses for forms are to let the web user contact us, fill.
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.
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.
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
Tutorial 6 Working with Web Forms
ITM 352 HTML Forms, Basic Form Processing
How to Write Web Forms By Mimi Opkins.
HTML Forms Pat Morin COMP 2405.
>> More on HTML Forms
(and available form fields)
FORMS Explained By: Sarbjit Kaur.
ITE 115 Creating Web Page Forms
HTML/XHTML Forms 18-Sep-18.
Designing Forms Lesson 10.
1.5 FORMS.
Creating Form Elements
Forms Data Entry and Capture
FORM OBJECT When creating an interactive web site for the Internet it is necessary to capture user input and process this input. Based on the result of.
Forms, cont’d.
CNIT 131 HTML5 - Forms.
Intro to Forms HTML forms are used to gather information from end-users. A form can contain elements like radio-buttons, text fields, checkboxes, submit.
HTML Forms 18-Apr-19.
Intro to Forms HTML forms are used to gather information from end-users. A form can contain elements like radio-buttons, text fields, checkboxes, submit.
Presentation transcript:

BBK P1 Module2010/11 : [‹#›] Forms (Getting data from users)

BBK P1 Module2010/11 : [‹#›] Forms: how they work We need to know.. 1.How forms work. 2.How to write forms in XHTML. 3.How to access the data in PHP.

BBK P1 Module2010/11 : [‹#›] How forms work Web Server User User requests a particular URL XHTML Page supplied with Form User fills in form and submits. Another URL is requested and the Form data is sent to this page either in URL or as a separate piece of data. XHTML Response

BBK P1 Module2010/11 : [‹#›] XHTML Form The form is enclosed in form tags.. <form action=“path/to/submit/page” method=“get”>

BBK P1 Module2010/11 : [‹#›] Form tags action=“…” is the page that the form should submit its data to. method=“…” is the method by which the form data is submitted. The option are either get or post. If the method is get the data is passed in the url string, if the method is post it is passed as a separate file.

BBK P1 Module2010/11 : [‹#›] Form fields: text input Use a text input within form tags for a single line freeform text input. First Name <input type="text" name="firstname" id=“fn" size="20"/>

BBK P1 Module2010/11 : [‹#›] Form tags name=“…” is the name of the field. You will use this name in PHP to access the data. id=“…” is label reference string – this should be the same as that referenced in the tag. size=“…” is the length of the displayed text box (number of characters).

BBK P1 Module2010/11 : [‹#›] Form fields: password input Use a starred text input for passwords. Password <input type=“password" name=“passwd" id=“pw" size="20"/>

BBK P1 Module2010/11 : [‹#›] Form fields: text input If you need more than 1 line to enter data, use a textarea. Description <textarea name=“description” id=“desc“ rows=“10” cols=“30”> Default text goes here…

BBK P1 Module2010/11 : [‹#›] Form fields: text area name=“…” is the name of the field. You will use this name in PHP to access the data. id=“…” is label reference string – this should be the same as that referenced in the tag. rows=“…” cols=“..” is the size of the displayed text box.

BBK P1 Module2010/11 : [‹#›] Form fields: drop down Where do you live? Swindon <option value="london” selected="selected">London Bristol

BBK P1 Module2010/11 : [‹#›] Form fields: drop down name=“…” is the name of the field. id=“…” is label reference string. <option value=“…” is the actual data sent back to PHP if the option is selected. … is the value displayed to the user. selected=“selected” this option is selected by default.

BBK P1 Module2010/11 : [‹#›] Form fields: radio buttons <input type="radio" name="age" id="u30“ checked=“checked” value="Under30" /> Under 30 <input type="radio" name="age" id="thirty40" value="30to40" /> 30 to 40

BBK P1 Module2010/11 : [‹#›] Form fields: radio buttons name=“…” is the name of the field. All radio boxes with the same name are grouped with only one selectable at a time. id=“…” is label reference string. value=“…” is the actual data sent back to PHP if the option is selected. checked=“checked” this option is selected by default.

BBK P1 Module2010/11 : [‹#›] Form fields: check boxes What colours do you like? <input type="checkbox" name="colour[]" id="r" checked="checked" value="red" /> Red <input type="checkbox" name="colour[]" id="b" value="blue" /> Blue

BBK P1 Module2010/11 : [‹#›] Form fields: check boxes name=“…” is the name of the field. Multiple checkboxes can be selected, so if the button are given the same name, they will overwrite previous values. The exception is if the name is given with square brackets – an array is returned to PHP. id=“…” is label reference string. value=“…” is the actual data sent back to PHP if the option is selected. checked=“checked” this option is selected by default.

BBK P1 Module2010/11 : [‹#›] Hidden Fields <input type="hidden" name="hidden_value" value="My Hidden Value" /> name=“…” is the name of the field. value=“…” is the actual data sent back to PHP.

BBK P1 Module2010/11 : [‹#›] Submit button.. A submit button for the form can be created with the code: <input type="submit" name="submit" value="Submit" />

BBK P1 Module2010/11 : [‹#›] Fieldset In XHTML 1.0, all inputs must be grouped within the form into a block-level element. XHTML provides us with fieldsets to achieve this. These represent logical divisions through larger forms. For short forms, all inputs are contained in a single fieldset.

BBK P1 Module2010/11 : [‹#›] HOE 9: Creating Forms

BBK P1 Module2010/11 : [‹#›] In PHP… The form variables are available to PHP in the page to which they have been submitted. The variables are available in two superglobal arrays created by PHP called $_POST and $_GET.

BBK P1 Module2010/11 : [‹#›] Access data Access submitted data in the relevant array for the submission type, using the input name as a key. <form action=“path/to/submit/page” method=“get”> $ = $_GET[‘ ’];

BBK P1 Module2010/11 : [‹#›] A warning.. NEVER TRUST USER INPUT Always check what has been input. Validation can be undertaken using Regular expressions or in-built PHP functions.

BBK P1 Module2010/11 : [‹#›] A useful tip.. I find that storing the validated data in a different array to the original useful. I often name this array ‘clean’ or something similarly intuitive. I then *only* work with the data in $clean, and never refer to $_POST/$_GET again.

BBK P1 Module2010/11 : [‹#›] Example $clean = array(); if (ctype_alnum($_POST['username'])) { $clean['username'] = $_POST['username']; }

BBK P1 Module2010/11 : [‹#›] Filter example $clean = array(); if (ctype_alnum($_POST['username'])) { $clean['username'] = $_POST['username']; } $clean = array(); Initialise an array to store filtered data.

BBK P1 Module2010/11 : [‹#›] Filter example $clean = array(); if (ctype_alnum($_POST['username'])) { $clean['username'] = $_POST['username']; } if (ctype_alnum($_POST['username'])) Inspect username to make sure that it is alphanumeric.

BBK P1 Module2010/11 : [‹#›] Filter example $clean = array(); if (ctype_alnum($_POST['username'])) { $clean['username'] = $_POST['username']; } $clean['username'] = $_POST['username']; If it is, store it in the array.

BBK P1 Module2010/11 : [‹#›] Is it submitted? We also need to check before accessing data to see if the data is submitted, use isset() function. if (isset($_POST[‘username’])) { // perform validation }

BBK P1 Module2010/11 : [‹#›] HOE 10 : Accessing User Input