600-152 People Data and the Web Forms and CGI. HTML forms. A user interface to CGI applications



Similar documents
People Data and the Web Forms and CGI CGI. Facilitating interactive web applications

at () in C:\wamp\www\icaatom-1.2.0\icaatom \plugins\sfLucenePlugin\lib\vendor\Zend\Search\Lucene\Document.php line

How to write a CGI for the Apache Web server in C

Forms, CGI Objectives. HTML forms. Form example. Form example...

Chapter 8. Forms and Form Processing

8/9/16. Server-Side Web Programming Intro. The Hamburger Model. To make a Web server based program

CGI An Example. CGI Model (Pieces)

Chapter 2: Interactive Web Applications

Internet Technologies

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

2- Forms and JavaScript Course: Developing web- based applica<ons

10. Java Servelet. Introduction

Further web design: HTML forms

HTML Forms and CONTROLS

<option> eggs </option> <option> cheese </option> </select> </p> </form>

Configuring iplanet 6.0 Web Server For SSL and non-ssl Redirect

HTML Tables. IT 3203 Introduction to Web Development

How to Run an Apache HTTP Server With a Protocol

Working with forms in PHP

Web Services April 21st, 2009 with Hunter Pitelka

JavaScript and Dreamweaver Examples

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

Hypertext for Hyper Techs

Viewing Form Results

Web Programming with PHP 5. The right tool for the right job.

CS412 Interactive Lab Creating a Simple Web Form

Web development... the server side (of the force)

USING CGI WITH LABVIEW

HTML Forms. Pat Morin COMP 2405

Dynamic Content. Dynamic Web Content: HTML Forms CGI Web Servers and HTTP

Dynamic Web-Enabled Data Collection

07 Forms. 1 About Forms. 2 The FORM Tag. 1.1 Form Handlers

Hello World RESTful web service tutorial

Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)

Introduction to Server-Side Programming. Charles Liu

Perl/CGI. CS 299 Web Programming and Design

TCP/IP Networking An Example

INTRUSION DETECTION AND PREVENTION SYSTEM: CGI ATTACKS. A Thesis. Presented to. The Faculty of the Department of Computer Science

Chapter 22 How to send and access other web sites

APACHE HTTP SERVER 2.2.8

Short notes on webpage programming languages

Programming the Web 06CS73 SAMPLE QUESTIONS

WIRIS quizzes web services Getting started with PHP and Java

Tutorial 6 Creating a Web Form. HTML and CSS 6 TH EDITION

PHP Authentication Schemes

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Major Subject

XHTML Forms. Form syntax. Selection widgets. Submission method. Submission action. Radio buttons

CGI Programming on the World Wide Web


Web Programming. Robert M. Dondero, Ph.D. Princeton University

HTTP Response Splitting

Chapter 27 Hypertext Transfer Protocol

JavaScript Basics & HTML DOM. Sang Shin Java Technology Architect Sun Microsystems, Inc. sang.shin@sun.com

Intell-a-Keeper Reporting System Technical Programming Guide. Tracking your Bookings without going Nuts!

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

2. Follow the installation directions and install the server on ccc

XHTML BASICS. Institute of Finance Management CIT Department Herman Mandari

Web Design and Development ACS Chapter 13. Using Forms 11/30/2015 1

Inserting the Form Field In Dreamweaver 4, open a new or existing page. From the Insert menu choose Form.

Introduction to XHTML. 2010, Robert K. Moniot 1

By Glenn Fleishman. WebSpy. Form and function

LAB MANUAL CS (22): Web Technology

Web Development 1 A4 Project Description Web Architecture

Website Login Integration

The Basics of Dynamic SAS/IntrNet Applications Roderick A. Rose, Jordan Institute for Families, School of Social Work, UNC-Chapel Hill

Cyber Security Workshop Ethical Web Hacking

JAVASCRIPT AND COOKIES

Protocolo HTTP. Web and HTTP. HTTP overview. HTTP overview

Part II of The Pattern to Good ILE. with RPG IV. Scott Klement

Anatomy of a Pass-Back-Attack: Intercepting Authentication Credentials Stored in Multifunction Printers

Yandex.Widgets Quick start

Contents. 2 Alfresco API Version 1.0

CGI Programming. What is CGI?

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

InPost UK Limited GeoWidget Integration Guide Version 1.1

JavaScript: Arrays Pearson Education, Inc. All rights reserved.

Understanding Cross Site Scripting

Method of control. Lots of ways to architect C&C: Star topology; hierarchical; peer-to-peer Encrypted/stealthy communication.

HTTP/2: Operable and Performant. Mark

Form Mail Tutorial. Introduction. The cgi-bin

LICENSE4J AUTO LICENSE GENERATION AND ACTIVATION SERVER USER GUIDE

FORM-ORIENTED DATA ENTRY

Package httprequest. R topics documented: February 20, 2015

Sample HP OO Web Application

Project #2. CSE 123b Communications Software. HTTP Messages. HTTP Basics. HTTP Request. HTTP Request. Spring Four parts

PHP Form Handling. Prof. Jim Whitehead CMPS 183 Spring 2006 May 3, 2006

CloudOYE CDN USER MANUAL

Cover Page. Dynamic Server Pages Guide 10g Release 3 ( ) March 2007

WWW. World Wide Web Aka The Internet. dr. C. P. J. Koymans. Informatics Institute Universiteit van Amsterdam. November 30, 2007

Outline Definition of Webserver HTTP Static is no fun Software SSL. Webserver. in a nutshell. Sebastian Hollizeck. June, the 4 th 2013

INT322. By the end of this week you will: (1)understand the interaction between a browser, web server, web script, interpreter, and database server.

TCP/IP Networking, Part 2: Web-Based Control

InternetVista Web scenario documentation

CGI PROGRAMMING nd Edition. Perl for the World Wide Web by JACQUELINE D. HAMILTON

How To Use Ngnix (Php) With A Php-Fpm (Php-Fmm) On A Web Server (Php5) On Your Web Browser) On An Ubuntu Web Server On A Raspberry Web 2.5 (Net

Transcription:

HTML forms A user interface to CGI applications

Outline A simple example form. GET versus POST. cgi.escape(). Input controls.

A very simple form <html> <head> <title>a simple form</title> </head> <body> <h1>a simple form</h1> </body> </html> <form method="post" action="http://localhost/~bjpop/env.py"> <input type="text" name="foo" /> <input type="submit" /> </form>

The simple form looks like this in Safari

A very simple form <html> <head> <title>a simple form</title> </head> <body> <h1>a simple form</h1> <form method="post" action="http://localhost/~bjpop/env.py"> <input type="text" name="foo" /> <input type="submit" /> </form> </body> </html> Usual HMTL stuff. Note the use of xhtml syntax. Probably should declare DOCTYPE and the xhtml namespace for validation purposes, but we are keeping it short for the sake of these slides.

A very simple form The form element, containing two control elements. <html> <head> <title>a simple form</title> </head> <body> <h1>a simple form</h1> </body> </html> <form method="post" action="http://localhost/~bjpop/env.py"> <input type="text" name="foo" /> <input type="submit" /> </form>

A very simple form The first control element is a text input box. The name of the control is foo. <html> <head> <title>a simple form</title> </head> <body> <h1>a simple form</h1> </body> </html> <form method="post" action="http://localhost/~bjpop/env.py"> <input type="text" name="foo" /> <input type="submit" /> </form>

A very simple form <html> <head> <title>a simple form</title> </head> <body> <h1>a simple form</h1> </body> </html> <form method="post" action="http://localhost/~bjpop/env.py"> <input type="text" name="foo" /> <input type="submit" /> </form> The second control element is a submit button. When the user clicks on the button, the form data is sent to the server.

A very simple form <html> <head> <title>a simple form</title> </head> <body> <h1>a simple form</h1> <form method="post" action="http://localhost/~bjpop/env.py"> <input type="text" name="foo" /> <input type="submit" /> </form> </body> </html> The method attribute of the form element says how the form data is sent to the server. It can either be get or post. It determines the underlying HTTP request method used by the client.

A very simple form <html> <head> <title>a simple form</title> </head> <body> <h1>a simple form</h1> <form method="post" action="http://localhost/~bjpop/env.py"> <input type="text" name="foo" /> <input type="submit" /> </form> </body> </html> The action attribute of the form element determines which CGI script the form data should be sent to for processing.

The form in action 1. Type some text into the input box. 2. Click on the submit button.

HTTP_REFERER = http://localhost/~bjpop/forms-lecture/simpleform.html SERVER_SOFTWARE = Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 SCRIPT_NAME = /~bjpop/env.py SERVER_SIGNATURE = REQUEST_METHOD = POST SERVER_PROTOCOL = HTTP/1.1 QUERY_STRING = PATH = /usr/bin:/bin:/usr/sbin:/sbin CONTENT_LENGTH = 27 Output from the env.py CGI script. HTTP_USER_AGENT = Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-us)... HTTP_CONNECTION = keep-alive SERVER_NAME = localhost REMOTE_ADDR = ::1 SERVER_PORT = 80 SERVER_ADDR = ::1 DOCUMENT_ROOT = /Library/WebServer/Documents SCRIPT_FILENAME = /Users/bjpop/Sites/env.py SERVER_ADMIN = you@example.com HTTP_HOST = localhost REQUEST_URI = /~bjpop/env.py HTTP_ACCEPT = text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/ plain;q=0.8,image/png,*/*;q=0.5 GATEWAY_INTERFACE = CGI/1.1 REMOTE_PORT = 51901 HTTP_ACCEPT_LANGUAGE = en-us CONTENT_TYPE = application/x-www-form-urlencoded HTTP_ACCEPT_ENCODING = gzip, deflate stdin = foo=who+let+the+dogs+out%3f

HTTP_REFERER = http://localhost/~bjpop/forms-lecture/simpleform.html SERVER_SOFTWARE = Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 SCRIPT_NAME = /~bjpop/env.py SERVER_SIGNATURE = REQUEST_METHOD = POST SERVER_PROTOCOL = HTTP/1.1 QUERY_STRING = PATH = /usr/bin:/bin:/usr/sbin:/sbin CONTENT_LENGTH = 27 HTTP_USER_AGENT = Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-us)... HTTP_CONNECTION = keep-alive SERVER_NAME = localhost REMOTE_ADDR = ::1 SERVER_PORT = 80 SERVER_ADDR = ::1 DOCUMENT_ROOT = /Library/WebServer/Documents SCRIPT_FILENAME = /Users/bjpop/Sites/env.py SERVER_ADMIN = you@example.com HTTP_HOST = localhost REQUEST_URI = /~bjpop/env.py HTTP_ACCEPT = text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/ plain;q=0.8,image/png,*/*;q=0.5 GATEWAY_INTERFACE = CGI/1.1 REMOTE_PORT = 51901 HTTP_ACCEPT_LANGUAGE = en-us CONTENT_TYPE = application/x-www-form-urlencoded HTTP_ACCEPT_ENCODING = gzip, deflate stdin = foo=who+let+the+dogs+out%3f The form used method= post, so the REQUEST_METHOD is POST. The QUERY_STRING is empty because POST sends the data via standard input (stdin). Data from the input box called foo. Note that the data is encoded. Spaces have been replaced with +, and the question mark is encoded as %3F.

GET versus POST <html> <head> <title>a simple form</title> </head> <body> <h1>a simple form</h1> <form method="get" action="http://localhost/~bjpop/env.py"> <input type="text" name="foo" /> <input type="submit" /> </form> </body> </html> Change the method to get.

HTTP_REFERER = http://localhost/~bjpop/forms-lecture/simpleform.html SERVER_SOFTWARE = Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 SCRIPT_NAME = /~bjpop/env.py SERVER_SIGNATURE = REQUEST_METHOD = GET SERVER_PROTOCOL = HTTP/1.1 QUERY_STRING = foo=who+let+the+dogs+out%3f PATH = /usr/bin:/bin:/usr/sbin:/sbin HTTP_USER_AGENT = Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1 HTTP_CONNECTION = keep-alive SERVER_NAME = localhost REMOTE_ADDR = ::1 SERVER_PORT = 80 SERVER_ADDR = ::1 DOCUMENT_ROOT = /Library/WebServer/Documents SCRIPT_FILENAME = /Users/bjpop/Sites/env.py SERVER_ADMIN = you@example.com HTTP_HOST = localhost HTTP_CACHE_CONTROL = max-age=0 REQUEST_URI = /~bjpop/env.py?foo=who+let+the+dogs+out%3f Output from the env.py CGI script, when the form uses the get method instead of the post method. HTTP_ACCEPT = text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/ plain;q=0.8,image/png,*/*;q=0.5 GATEWAY_INTERFACE = CGI/1.1 REMOTE_PORT = 52008 HTTP_ACCEPT_LANGUAGE = en-us HTTP_ACCEPT_ENCODING = gzip, deflate stdin =

GET versus POST At the time of writing POST is not working properly on IVLE (oops). Hopefully it will be fixed soon. In the meantime, just use the get method for forms. In general, get is recommended only for idempotent requests. A request is idempotent if it returns the same result every time it is run. An idempotent request does not have side effects. That is, it does not change the state of the server. For example, it does not cause a file on the server to be modified. Why do you think this is this recommended?

An alternative CGI script for the action import cgi Assume that this script is called foo.py. print 'Content-Type: text/html' print store = cgi.fieldstorage() print '<html><head></head><body><h1>' if 'foo' in store: print store.getvalue('foo') print '</h1></body></html>'

Modify the action attribute to point to foo.py <html> <head> <title>a simple form</title> </head> <body> <h1>a simple form</h1> <form method="post" action="http://localhost/~bjpop/foo.py"> <input type="text" name="foo" /> <input type="submit" /> </form> </body> </html> Letʼs send the form data to foo.py instead of env.py.

The foo.py script in action. who let the dogs out?

The foo.py script in action. This is really the HTML: <html><head></head><body><h1> who let the dogs out? </h1></body></html> who let the dogs out?

The foo.py script in action. Notice that the string is decoded automatically by the Python cgi library. who let the dogs out?

Warning! import cgi print 'Content-Type: text/html' print store = cgi.fieldstorage() Danger! Danger! What happens if the user types html tags in the input box? print '<html><head></head><body><h1>' if 'foo' in store: print store.getvalue('foo') print '</h1></body></html>'

The user types HTML tags into the input text. This is really the HTML: <html><head></head><body><h1> <i>who</i> let the dogs out? </h1></body></html> who let the dogs out?

cgi.escape() import cgi print 'Content-Type: text/html' print store = cgi.fieldstorage() Now it is safe. print '<html><head></head><body><h1>' if 'foo' in store: print cgi.escape(store.getvalue('foo')) print '</h1></body></html>'

cgi.escape() This is really the HTML: <html><head></head><body><h1> <i>who</i> let the dogs out? </h1></body></html> <i>who</i> let the dogs out?

Input controls HTML forms provide several input controls, for example: text input boxes (single line and multi-line) checkboxes radio buttons submit button reset button buttons (other than submit and reset) menus hidden fields

Input controls We don t have time to cover all the controls in the lecture. You will try them out in next week s workshop. See: http://www.w3.org/tr/html401/interact/forms.html

A form with a few different controls <form method="get" action="http://localhost/~bjpop/env.py"> Enter something: <input type="text" name="mytextbox" value="a default value" /> <br /> <input type="checkbox" name="mycheckbox1" /> <input type="checkbox" name="mycheckbox2" checked="checked" /> <br /> <input type="radio" name="myradio" value="value1" checked="checked" /> <input type="radio" name="myradio" value="value2" /> <input type="radio" name="myradio" value="value3" /> <br /> <input type="submit" /> <input type="reset" /> </form>

The form looks like this in Safari

A form with a few different controls <form method="get" action="http://localhost/~bjpop/env.py"> Enter something: <input type="text" name="mytextbox" value="a default value" /> <br /> <input type="checkbox" name="mycheckbox1" /> <input type="checkbox" name="mycheckbox2" checked="checked" /> <br /> <input type="radio" name="myradio" value="value1" checked="checked" /> <input type="radio" name="myradio" value="value2" /> <input type="radio" name="myradio" value="value3" /> <br /> <input type="submit" /> <input type="reset" /> </form> Controls are identified by their name. Radio buttons (and also check boxes) are grouped together by using the same name.

A form with a few different controls <form method="get" action="http://localhost/~bjpop/env.py"> Enter something: <input type="text" name="mytextbox" value="a default value" /> <br /> <input type="checkbox" name="mycheckbox1" /> <input type="checkbox" name="mycheckbox2" checked="checked" /> <br /> <input type="radio" name="myradio" value="value1" checked="checked" /> <input type="radio" name="myradio" value="value2" /> <input type="radio" name="myradio" value="value3" /> <br /> <input type="submit" /> <input type="reset" /> </form> Some controls, such as text boxes, can have default values.

A form with a few different controls <form method="get" action="http://localhost/~bjpop/env.py"> Enter something: <input type="text" name="mytextbox" value="a default value" /> <br /> <input type="checkbox" name="mycheckbox1" /> <input type="checkbox" name="mycheckbox2" checked="checked" /> <br /> <input type="radio" name="myradio" value="value1" checked="checked" /> <input type="radio" name="myradio" value="value2" /> <input type="radio" name="myradio" value="value3" /> <br /> <input type="submit" /> <input type="reset" /> </form> Checkboxes and radio buttons can be checked by default.

Let s submit this form to env.py sent to env.py using the get method QUERY_STRING = mytextbox=who+let+the+dogs+out%3f&mycheckbox1=on&mycheckbox2=on&myradio=value2

Let s submit this form to env.py sent to env.py using the get method QUERY_STRING = mytextbox=who+let+the+dogs+out%3f&mycheckbox1=on&mycheckbox2=on&myradio=value2 See how the names of the controls are sent in the QUERY_STRING

Let s submit this form to env.py sent to env.py using the get method QUERY_STRING = mytextbox=who+let+the+dogs+out%3f&mycheckbox1=on&mycheckbox2=on&myradio=value2 Checkboxes which are selected get the value on by default, but you can also use custom values via the value attribute.

A (slightly) more interesting CGI script for our form import cgi Assume that this script is called bar.py. print 'Content-Type: text/html' print store = cgi.fieldstorage() print '<html><head></head><body><table border="1">' print '<tr><th>name</th><th>value</th></tr>' for var in store: value = cgi.escape(store.getvalue(var)) print '<tr><td>%s</td><td>%s</td></tr>' % (var, value) print '</table></body></html>'

Let s submit this form to bar.py sent to bar.py using the get method

Remarks A single HTML document can contain multiple forms, and hence multiple submit buttons. However, forms cannot be nested. That is, one form cannot be inside another. It is possible to write the CGI script to produce a form as output, and also act as the recipient of the form data (by being the action of the form).

Homework - make a form that looks like this

In the next lecture Cookies for tracking user identity.