CGI in Context CGI is Common Gateway Interface, supporting a greater degree of interaction between the user and a Web page, most commonly by means of a.

Slides:



Advertisements
Similar presentations
Web forms and CGI scripts Dr. Andrew C.R. Martin
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 14 HTML Forms CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
JavaScript Forms Form Validation Cookies CGI Programs.
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.
USER INTERACTIONS: FORMS
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.
Creating Web Page Forms
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Chapter 10 Form Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
CST JavaScript Validating Form Data with JavaScript.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
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.
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
Forms and Form Controls Chapter What is a Form?
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
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 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Internet / Intranet Fall 2000 Class 7. Brandeis University Internet/Intranet Spring Class 7 Agenda Project / Homework Discussion Forms Validating.
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.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
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.
ITCS373: Internet Technology Lecture 5: More HTML.
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.
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 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.
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.
HTML Forms.
Week 10: HTML Forms HNDIT11062 – Web Development.
Basic Webpage Design HTML Forms. Objectives Learn how to use HTML to create a form. Explain the concept of forms Know the difference of GET and POST Discuss.
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.
Creating Forms on a Web Page. 2 Introduction  Forms allow Web developers to collect visitor feedback  Forms create an environment that invites people.
Copyright (c) 2004 Prentice-Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Project 6: Creating XHTML Forms Kelly.
1 HTML forms (cont.)
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
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.
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
How to Write Web Forms By Mimi Opkins.
ITE 115 Creating Web Page Forms
Designing Forms Lesson 10.
Creating Form Elements
Web Development & Design Foundations with H T M L 5
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.
CNIT 131 HTML5 - Forms.
Creating Forms on a Web Page
Lesson 6: Web Forms.
Unit 5 Create Forms.
Presentation transcript:

CGI in Context CGI is Common Gateway Interface, supporting a greater degree of interaction between the user and a Web page, most commonly by means of a FORM. A FORM contains a number of elements each of which has a name. When the form is submitted a list of names and values is transmitted, using CGI protocols, indicating the contents of the form.

CGI processes The server transmits the document over the communication link. The browser renders the document, including the FORM. The user completes the FORM and submits it. The name/value pairs from the FORM are transmitted back to the server. The server starts the process identified in the FORM header and supplies the name/value pairs to it. The process takes some action, determined by the name/value pairs, and outputs a properly formatted HTML document. The HTML document produced by the process is returned to the browser as the response from the server to the user's input on the original FORM.

Form Basics <FORM ACTION = " cgiwrap\~fintan\cgiteach\test.cgi" METHOD = "POST"> Details of the form here The ACTION argument should be all on one line, it identifies the server-side process which will accept the information from the form and return a reply to the browser. The METHOD should always be POST. The server-side process given does exist and will return a list of name/value pairs from the form.

Submit & Reset Buttons <INPUT TYPE=SUBMIT NAME=CgiName VALUE="Button Label" > Pressing a submit button will transmit all the name/value pairs from the browser to the server <INPUT TYPE=RESET VALUE="Button Label" > Pressing a reset button will cause the form to clear all components back their default values

INPUT - TEXT Element <INPUT TYPE=TEXT NAME=CgiName {SIZE=VisibleSize} VALUE="Initial Value"> TEXT elements supply a single-line text input area. The SIZE argument determines the (approximate) number of characters to display, not the maximum number that can be entered. The VALUE argument determines the default contents.

SELECT - Pull-down menu OptionName etc. etc. etc. The options will be presented on a pull-down menu, with the first selected by default. The value part of the name/value pair will be the item selected when the form is submitted.

INPUT - Radio Buttons <INPUT TYPE=RADIO NAME=Colour VALUE=Red > Red <INPUT TYPE=RADIO NAME=Colour VALUE=Orange > Orange All tags with the same NAME act as a set of radio buttons and the value submitted will be the VALUE of the selected radio button. The button label is not the VALUE, but the text between the and tags.

INPUT - check boxes The TYPE argument specifies a checkbox, CHECKED specifies that it should be ticked by default. Only boxes that are ticked will send a NAME/VALUE pair to the server. If more then one checkbox has the same name a list of VALUEs is sent. <INPUT TYPE=CHECKBOX CHECKED NAME=Colour VALUE=Red > Red <INPUT TYPE= CHECKBOX NAME=Colour VALUE=Orange > Orange

SELECT - selection box The SIZE argument indicates that a element should be a selection box, not a pull-down menu. MULTIPLE indicates that more than one element may be selected. <SELECT NAME=CgiName SIZE=NumberVisible MULTIPLE> OptionName etc. etc. etc. The NAME/VALUE pair will not be sent if none are selected and will be a list if more than one is selected.

TEXTAREA COLS & ROWS, if specified, override the default size. They only specify the visible size of the field and do not prevent the user from typing much more. The entire contents are sent as the VALUE part of the NAME/VALUE pair. <TEXTAREA NAME=CgiName COLS=NumCols ROWS=NumRows> Default contents

PASSWORD A single line text field which does not echo the user’s input as they type. But should not be assumed to be secure when transmitted across the Web. <INPUT TYPE=PASSWORD NAME=CgiName VALUE="Default" >

IMAGES Acts as a SUBMIT button in its own right. In this format sends two name value pairs, CgiName.x and CgiName.y, containing the location of the mouse pointer when it was clicked. More complex formats allow server- or client- side image maps that can associate links with various parts of the image. <INPUT TYPE=IMAGE NAME=CgiName SRC=Filename>

Form Usability Layout of a FORM is vital if it is to be used effectively. The sequence in which the fields are presented and the language used to indicate to the user what to do are important. The most effective layouts can only be attained by using a to ensure that fields are vertically aligned. Using CGI it is not possible to validate a user’s input until the form is complete and has been submitted. Combined with the latency of the Web this can be very frustrating. Client-side scripting (next two lectures) can be used to validate upon entry or upon submission.

CGI Process The form processing in these notes will use Tcl, not PERL. <FORM ACTION=“ ~myuserid/mycgiscript.cgi” METHOD = POST> The ACTION argument has to be on a single line and identifies the name of a file ( mycgiscript.cgi ) which must be in the cgi-bin subdirectory of the.public_html directory and must have execute permissions. #!/usr/local/bin/bash export env./myformexample.tcl This is a minimal.cgi file that exports the current environment and then starts a tcl process. The tcl process is scripted in the source myformexample.tcl, which must also have execute permission.

AddUp FORM <FORM ACTION=" ~fintan\addup.cgi" METHOD="POST"> Enter two numbers and then press Submit.

addup.tcl #!/usr/local/bin/tclsh # Filename myformexample.tcl. Example Tcl CGI # script. # # Fintan Culwin, v0.1, March source GetPostedData.tcl GetPostedData The first thing the tcl process has to do is to decode the CGI protocol encoded name/value pairs. There are two ways to do this …. Write your own routine … Copy one from ~fintan/.public_html/cgi-bin/GetPostedData.tcl Assuming that you have done this, and copied GetPostedData.tcl into your cgi-bin directory, the start of the addup.tcl file is: This calls the GetPostedData routine and places the values into an associative array whose index values are the names.

addup.tcl - HTML header # Output the appropriate MIME header puts "Content-type: text/html” puts "” # Output a complete HTML header.... puts " \n " puts " \nAdd Up Script\n " puts " \n\n " Which produces this on the tcl processes’ output stream. This stream is connected back to the browser which submitted the form in the first place. Content-type: text/html Add Up Script

addup.tcl - 3 puts " \nThis document was generated " puts -nonewline "by a tickle script on ” puts -nonewline [ exec date ] puts ".\n \n " This document was generated by a tickle script on Tue Mar 5 12:27:16 GMT 1996.

addup.tcl - 4 # Calculate the answer set TheAnswer [ expr $FormData(FirstNumber) $FormData(SecondNumber)] # Send the information back to the browser puts " \n$FormData(FirstNumber) “ puts “ plus $FormData(SecondNumber) \n" puts "is $TheAnswer. \n " 54 plus 22 \n is 76.

addup.tcl - 5 puts " ” puts -nonewline " ” puts "Return to FORMs addup example.” puts " \n \n \n ” puts “ ” Return to FORMs, addup example.

Visitor’s Book - Context In this the information received from the form is used to update files held on the server, and the contents of those files are used to supply the contents of the reply.

Visitor’s Book - HTML <FORM ACTION=" ~fintan\visitor.cgi" METHOD="POST"> Visitor's Book Please enter your personal name and your family name

Visitor’s Book - CGI - 1 puts "Content-type: text/html" puts "" # Output a complete HTML header.... puts " \n " puts " \nVisitor's Book\n " puts " \n\n " # Obtain the data from the form GetPostedData puts " Mr. Blobby's Visitor's Book\n \n " if { ( [ info exists FormData(PersName)]) && ( [ info exists FormData(FamName)]) } { ProcessForm } else { puts " \nThank you for visiting my home page.\n " puts " Maybe next time you will leave your name.\n \n " } This makes sure that the user has replied.

Visitor’s Book - CGI - 2 proc ProcessForm {} { global FormData # Store the information from the form (in html) format # at the end of a file called 'visitors.dat'. # Open the file in append (a) mode. set FileId [ open visitors.dat a ] # Write the information in HTML format as a single line puts -nonewline $FileId $FormData(PersName) puts -nonewline $FileId $FormData(FamName)" puts -nonewline $FileId " visited on " puts -nonewline $FileId [exec date] puts $FileId # close the visitors.dat file close $FileId This adds their details to the end of the visitors.dat file.

Visitor’s Book - CGI - 3 # Obtain the number of visitors from visitors.num file. set FileId [ open visitors.num r ] gets $FileId NumVisitors close $FileId # Then increment the value and return it to the file. incr NumVisitors set FileId [ open visitors.num w ] puts $FileId $NumVisitors close $FileId This obtains the number of visitors from the visitors.num file, increments it and writes it back to the file.

Visitor’s Book - CGI - 4 # Finally send the information back to the user. puts " \nHello $FormData(PersName)!" puts " " puts " Your are visitor number $NumVisitors. " puts "previous visitors have included:" puts " \n \n " set Visitors [exec tail visitors.dat] puts $Visitors puts " \n \n " puts "Please call again some time.." puts " " This writes the reply to the user, in HTML format, onto the output stream. (The Unix tail command will obtain the last 20 lines from the file specified).

Visitor’s Book - reply