CGI Programming Part 2. Input Tags Many different ways of getting data from the user. The tag is used most often. has a type attribute –Specifies the.

Slides:



Advertisements
Similar presentations
Web forms and CGI scripts Dr. Andrew C.R. Martin
Advertisements

CGI Programming.
Lecture 14 HTML Forms CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Video, audio, embed, iframe, HTML Form
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.
Python and Web Programming
USER INTERACTIONS: FORMS
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.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Forms. Form An HTML form is a section of a document containing normal content, special elements called controls (checkboxes, radio buttons, buttons, etc.),
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
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.
CO1552 Web Application Development HTML Forms. Websites can be made more interactive by providing facilities for users to provide data To get user entered.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
CSE 382/ETE 334 Internet and Web Technology Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
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 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:
HTML II. Factors to consider in designing a website. Organizing your files. HTML Tables. Unordered Lists. Ordered Lists. HTML Forms. Learning Objectives.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
2 1 Sending Data Using a Hyperlink CGI/Perl Programming By Diane Zak.
USING PERL FOR CGI PROGRAMMING
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Website Development with PHP and MySQL Saving Data.
CGI Programming. What is "CGI"? Common Gateway Interface A means of running an executable program via the Web. CGI is not a Perl-specific concept. Almost.
1 Basic Perl CGI Programming. 2 Issues How and when your program is invoked. Generating Response –HTTP Headers –HTML (or whatever document type you want)
1 HTML Forms
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
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.
Perl CGI What is "CGI"? Common Gateway Interface A means of running an executable program via the Web. Perl have a *very* nice interface to create CGI.
TJ 3043 – Web Application Development HTML Form. 2.0 Forms A form is the usual way to communicate information from a Web browser to a server HTML has.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
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.
TJ 3043 – Web Application Development HTML Form. 2.0 Forms - A form is the usual way information is gotten from a browser to a server - HTML has tags.
HTLM Forms CS3505. Form Handling in Browser html User Files out form WEbBROWSErWEbBROWSEr User read response submit Get URL?input html Get file html script.
Introduction To HTML Form Inputs Written By George Gimian.
+ 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.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
Project 6 Creating Forms on a Web Page. Objectives Define terms related to forms Describe the different form controls and their uses Use the tag Create.
Creating Web Page Forms COE 201- Computer Proficiency.
Netprog CGI and Forms1 CGI and Forms A detailed look at HTML forms.
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.
1 HTML forms (cont.)
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Chapter 5 © 2002 by Addison Wesley Longman, Inc. 1 Chapter 5 Sebesta: Programming the World Wide Web.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
How to Write Web Forms By Mimi Opkins.
CGI I: Basics Web Programming.
Basic XHTML Tables XHTML tables—a frequently used feature that organizes data into rows and columns. Tables are defined with the table element. Table.
Introducing Forms.
CGI Programming Part II UNIX Security
Forms, cont’d.
Creating Forms on a Web Page
CGI I: Basics Web Programming.
Presentation transcript:

CGI Programming Part 2

Input Tags Many different ways of getting data from the user. The tag is used most often. has a type attribute –Specifies the method with which to get data from the user.

Other Attributes of name – name of an input field. value – value of an input field. size – width of an input field. maxlength – maximum number of characters that can be entered in an input field. checked – whether a radio or checkbox is “turned on”. src – url of an image.

Input Type: Text Setting the type to text creates a text box. For example, <input type=“text” name=“street” size = 30> Note, name does not appear in the webpage. It is seen only by the CGI program.

Input Type: Radio Setting the type to radio creates a radio button. For example, Ms. Mrs. Mr. Dr. All related radio buttons have the same name. The values are all preset.

Input Type: Submit and Reset submit creates a submit button to contact a CGI program. For example, reset creates a button to erase all values in a form. For example, The “value” appears in the button.

Input Type: Others checkbox – creates a checkbox password – creates a password field. A text field with characters displayed as ****. button – creates a button the user can press. file – creates a field to upload a file. image – creates an image the user can click to submit a form.

Inputs Other Than - multi-line text field. You can specify the rows and cols attributes. - creates a drop down menu.

Handling the Input Input is sent to the CGI program specified in the tag using either the get or post method. It is best to write CGI programs that handle both. Can be done by examining the environment variable, REQUEST_METHOD.

An Example $request_method = $ENV{‘REQUEST_METHOD’}; if ($request_method eq “GET”) { $query_string = $ENV{‘QUERY_STRING’}; } elsif ($request_method eq “POST”) { read(STDIN, $query_string, $ENV{‘CONTENT_LENGTH’}); }

CGI.pm Many parts of CGI programs are repeated. –Makes sense to capture these parts for reuse. CGI.pm is a module of Perl functions to do many common tasks. Many functions provide shortcuts to create HTML. Module can be used as a collection of functions or an object oriented class.

Object-Oriented Use Can be used as an object-oriented class by: use CGI; … $q = new CGI; Access subroutines as methods of $q For example, print $q ->start_html();

Function-Oriented Use Import a set of functions to be called directly. –non-object oriented is often faster than object-oriented. Use a quoted list to tell Perl which functions to import. use CGI (“start_html”, “end_html”, “header”); CGI.pm also defines sets of these functions. ‘standard’ and ‘html3’ are the most common. use CGI qw(:standard :html3);

header The header function creates the HTTP header. The default is “text/html”. For example, print header(); creates print “Content-type: text/html\n\n”;

start_html start_html create the HTML header start_html can take one parameter, the title. For example, print start_html(‘My Home Page’); creates My Home Page

start_html (cont.) start_html can also take named parameters. Specify attributes to give to the tag. For example, print start_html (-title => “My Title”, -bgcolor => “Red”); creates My Title

end_html end_html creates the ending part of an HTML document. For example, print end_html(); creates

param param gets the parameter values sent to a CGI program. Query String: name=Max%20Powers&job=ceo Can get the query values by: $name = param(“name”); $job = param(“job”); This is the scalar context.

Contexts of param Can be called in list context with no arguments. Returns names of all parameters. = param(); Can be called in list context with an argument. Returns an array of all values for that argument. = param(“title”);

Locking Files Many webpages allow multiple users to access the same information. –i.e. multiple user writing to the same file. Need a mechanism to ensure consistency. –Do not want one user’s action to undo the actions of another. A file must be locked when being written to.

flock flock can be used to lock a file. The syntax is flock (filehandle, mode); Set mode to –2 to lock a file. –8 to unlock a file. For example, flock (FILE, 2);

Debugging Debugging a CGI script can be frustrating. Browser will display “500 Internal Server Error” if any errors occur. Some useful tips: –Run the program from the command line. –Use perl –c to see if file compiles.