More forms CS380 1. Reset Buttons  specify custom text on the button by setting its value attribute CS380 2 Name: Food: Meat? HTML.

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

23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
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.
CGI Programming.
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.
Chapter 6 Basic forms 1. Forms and query string 2 form : a group of user input (UI) controls that accepts information from the user and sends the information.
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
HTML Form Processing Learning Web Design – Chapter 9, pp Squirrel Book – Chapter 11, pp
Form Basics CS Web Data  Most interesting web pages revolve around data  examples: Google, IMDB, Digg, Facebook, YouTube, Rotten Tomatoes  can.
Python and Web Programming
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.
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.
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.
Uploading Files. Why? By giving a user the option to upload a file you are creating an interactive page You can enable users have a greater web experience.
CSE 154 LECTURE 9: FORMS. Web data most interesting web pages revolve around data examples: Google, IMDB, Digg, Facebook, YouTube, Rotten Tomatoes can.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
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.
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.
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.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
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.
Lecture 7 – Form processing (Part 2) SFDV3011 – Advanced Web Development 1.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
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:
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
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 PHPs to Insert, Update, and Delete Data CS 320.
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.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
SYST Web Technologies SYST Web Technologies XHTML Forms.
Web Technologies Lecture 3 Web forms. HTML5 forms A component of a webpage that has form controls – Text fields – Buttons – Checkboxes – Range controls.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
1 HTML forms (cont.)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
HTML Forms.
1 HTML forms (cont.)
CGS 3066: Web Programming and Design Spring 2016 PHP.
Web Services Essentials. What is a web service? web service: software functionality that can be invoked through the internet using common protocols like.
CSE 154 LECTURE 18: FORMS AND UPLOADING FILES. Exercise: Baby name web service JSON Modify our babynames.php service to produce its output as JSON. For.
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Radoslav Georgiev Telerik Corporation
Unit 7 How to Upload Files. A very useful aspect of PHP is its ability to manage file uploads to your server. Before you can use PHP to manage your uploads,
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
Advanced HTML Tags:.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
HTML Forms and Server-Side Data
DBW - PHP DBW2017.
Super Global Arrays Forms and PHP "Superglobal" arrays (6.4.1)
Lecture 19: Forms and uploading files
CNIT 131 HTML5 - Forms.
HTTP GET vs POST SE-2840 Dr. Mark L. Hornick.
CMPT241 Web Programming Chapter 6 Forms.
PHP-II.
Presentation transcript:

More forms CS380 1

Reset Buttons  specify custom text on the button by setting its value attribute CS380 2 Name: Food: Meat? HTML

Grouping input:,  fieldset groups related input fields, adds a border; legend supplies a caption CS380 3 Credit cards: Visa MasterCard American Express HTML

Common UI control errors  “I changed the form's HTML code... but when I refresh, the page doesn't update!”  By default, when you refresh a page, it leaves the previous values in all form controls  it does this in case you were filling out a long form and needed to refresh/return to it  if you want it to clear out all UI controls' state and values, you must do a full refresh Firefox: Shift-Ctrl-R Mac: Shift-Command-R CS380 4

Styling form controls  attribute selector: matches only elements that have a particular attribute value  useful for controls because many share the same element (input) CS380 5 input[type="text"] { background-color: yellow; font-weight: bold; } CSS

Hidden input parameters  an invisible parameter that is still passed to the server when form is submitted  useful for passing on additional state that isn't modified by the user CS380 6 Name SID HTML

Submitting data CS380 7

Problems with submitting data  the form may look correct, but when you submit it...  [cc] => on, [startrek] => Jean-Luc Picard  How can we resolve this conflict? CS380 8 Visa MasterCard Favorite Star Trek captain: James T. Kirk Jean-Luc Picard HTML

The value attribute  value attribute sets what will be submitted if a control is selected  [cc] => visa, [startrek] => picard CS380 9 Visa MasterCard Favorite Star Trek captain: James T. Kirk Jean-Luc Picard HTML

URL-encoding  certain characters are not allowed in URL query parameters:  examples: " ", "/", "=", "&"  when passing a parameter, it is URL-encoded  “Xenia's cool!?" → “Xenia%27s+cool%3F%21"  you don't usually need to worry about this:  the browser automatically encodes parameters before sending them  the PHP $_REQUEST array automatically decodes them ... but occasionally the encoded version does pop up (e.g. in Firebug) 10

Submitting data to a web server  though browsers mostly retrieve data, sometimes you want to submit data to a server  Hotmail: Send a message  Flickr: Upload a photo  Google Calendar: Create an appointment  the data is sent in HTTP requests to the server  with HTML forms  with Ajax (seen later)  the data is placed into the request as parameters 11 CS380

HTTP GET vs. POST requests  GET : asks a server for a page or data  if the request has parameters, they are sent in the URL as a query string  POST : submits data to a web server and retrieves the server's response  if the request has parameters, they are embedded in the request's HTTP packet, not the URL 12 CS380

HTTP GET vs. POST requests  For submitting data, a POST request is more appropriate than a GET  GET requests embed their parameters in their URLs  URLs are limited in length (~ 1024 characters)  URLs cannot contain special characters without encoding  private data in a URL can be seen or modified by users 13 CS380

Form POST example CS Name: Food: Meat? HTML

GET or POST?  some PHP pages process both GET and POST requests  to find out which kind of request we are currently processing, look at the global $_SERVER array's " REQUEST_METHOD " element CS if ($_SERVER["REQUEST_METHOD"] == "GET") { # process a GET request... } elseif ($_SERVER["REQUEST_METHOD"] == "POST") { # process a POST request... } PHP

Uploading files  add a file upload to your form as an input tag with type of file  must also set the enctype attribute of the form CS <form action=" method="post" enctype="multipart/form-data"> Upload an image as your avatar: HTML

Processing form data in PHP 17 CS380

"Superglobal" arrays  PHP superglobal arrays contain information about the current request, server, etc.  These are special kinds of arrays called associative arrays. 18

Associative arrays  associative array (a.k.a. map, dictionary, hash table) : uses non-integer indexes  associates a particular index "key" with a value  key “xenia" maps to value " " CS $blackbook = array(); $blackbook[“xenia”] = " "; $blackbook[“anne”] = " ";... print “Xenia's number is ". $blackbook[“xenia"]. ".\n"; PHP

Example: exponents  What should we do to run this with xampp? 20 <?php $base = $_REQUEST["base"]; $exp = $_REQUEST["exponent"]; $result = pow($base, $exp); ?> ^ = PHP CS380

Example: Print all parameters  What should we do to run this with xampp? 21 <?php foreach ($_REQUEST as $param => $value) { ?> Parameter has value <?php } ?> PHP CS380

Processing an uploaded file in PHP  uploaded files are placed into global array $_FILES, not $_REQUEST  each element of $_FILES is itself an associative array, containing:  name : the local filename that the user uploaded  type : the MIME type of data that was uploaded, such as image/jpeg  size : file's size in bytes  tmp_name : a filename where PHP has temporarily saved the uploaded file to permanently store the file, move it from this location into some other file 22

Uploading files  example: if you upload tobby.jpg as a parameter named avatar,  $_FILES["avatar"]["name"] will be “tobby.jpg"  $_FILES["avatar"]["type"] will be "image/jpeg"  $_FILES["avatar"]["tmp_name"] will be something like "/var/tmp/phpZtR4TI" CS HTML

CS Array ( [file1] => Array ( [name] => MyFile.txt (comes from the browser, so treat as tainted) [type] => text/plain (not sure where it gets this from - assume the browser, so treat as tainted) [tmp_name] => /tmp/php/php1h4j1o (could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted) [error] => UPLOAD_ERR_OK (= 0) [size] => 123 (the size in bytes) ) [file2] => Array ( [name] => MyFile.jpg [type] => image/jpeg [tmp_name] => /tmp/php/php6hst32 [error] => UPLOAD_ERR_OK [size] => ) ) PHP

Processing uploaded file example  functions for dealing with uploaded files:  is_uploaded_file(filename) returns TRUE if the given filename was uploaded by the user  move_uploaded_file(from, to) moves from a temporary file location to a more permanent file 25 $username = $_REQUEST["username"]; if (is_uploaded_file($_FILES["avatar"]["tmp_name"])) { move_uploaded_file($_FILES["avatar"]["tmp_name"], "$username/avatar.jpg"); print "Saved uploaded file as $username/avatar.jpg\n"; } else { print "Error: required file not uploaded"; } PHP

Including files: include  inserts the entire contents of the given file into the PHP script's output page  encourages modularity  useful for defining reused functions needed by multiple pages 26 include("header.php"); PHP CS380