Python, CGI November 23, Unit 8. So Far We can write programs in Python (in theory at least) –Conditionals –Variables –While loops We can create a form.

Slides:



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

Getting Input in Python Assumes assignment statement, typecasts.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
CGI Programming.
Tutorial 6 Working with Web Forms
 2002 Prentice Hall. All rights reserved. 1 Chapter 6 – Introduction to the Common Gateway Interface (CGI) Outline 6.1 Introduction 6.2 Client and Web.
Python November 14, Unit 7. Python Hello world, in class.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Python and Web Programming
Guide To UNIX Using Linux Third Edition
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.
Web Client/Server Communication A290/A590, Fall /09/2014.
1 Spidering the Web in Python CSC 161: The Art of Programming Prof. Henry Kautz 11/23/2009.
Did someone say Music? November 7, Adding MUSIC to a web page: 1. Find your music! 2. A good website is 3. You will.
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.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
ITIS 1210 Introduction to Web-Based Information Systems Chapter 24 How Websites Work with Databases How Websites Work with Databases.
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.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
GDT V5 Web Services. GDT V5 Web Services Doug Evans and Detlef Lexut GDT 2008 International User Conference August 10 – 13  Lake Las Vegas, Nevada GDT.
Python November 28, Unit 9+. Local and Global Variables There are two main types of variables in Python: local and global –The explanation of local and.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
Unit 3 Day 6 FOCS – Web Design. Journal Unit #3 Entry #4 Write the source code that would make the following display on a rendered page: Shopping List.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
Website Development with PHP and MySQL Saving Data.
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,
PHP Form Introduction Getting User Information Text Input.
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.
Button and Textbox. Input  Input objects are used to obtain input from the user viewing the webpage. They allow the user to interact with the Web. 
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
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.
Introduction to Programming the WWW I CMSC Winter 2003.
Graphical User Interface You will be used to using programs that have a graphical user interface (GUI). So far you have been writing programs that have.
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.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Implementing and Using the SIRWEB Interface Setup of the CGI script and web procfile Connecting to your database using HTML Retrieving data using the CGI.
Forms Overview, Query string, Submitting arrays, PHP & HTML, Input types, Redirecting the user Mario Peshev Technical Trainer Software.
Starting BBEdit or Notepad and Opening the HTML File Start BBEdit or Notepad Select Open from the File Menu Open survey1.htm from the Public Folder.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Form Processing Week Four. Form Processing Concepts The principal tool used to process Web forms stored on UNIX servers is a CGI (Common Gateway Interface)
HTML FORMS The TEXT Object Presented By: Ankit Gupta.
Week 10: HTML Forms HNDIT11062 – Web Development.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
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.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
Chapter 16 Web Pages And CGI Scripts Department of Biomedical Informatics University of Pittsburgh School of Medicine
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.)
Web Development Resources for Project 1 Tyler Moore University of Tulsa CS 7403: Secure Electronic Commerce Spring
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
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.
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
Forms Web Design Ms. Olifer.
Foundations of Programming: Arrays
Formatting Output.
JavaScript: Functions.
File Handling Programming Guides.
Creating Forms on a Web Page
HTML Forms What are clients? What are servers?
Presentation transcript:

Python, CGI November 23, Unit 8

So Far We can write programs in Python (in theory at least) –Conditionals –Variables –While loops We can create a form for our web page –Adding controls Now we need some way to take that form information and process it somehow

CGI Common Gateway Interface It’s how we are going to pass information from our form to a web script In this case we’ll be taking our form information and giving it to our Python script To use CGI in Python we have to include the CGI module

Accessing Form Information First, we must import the CGI module –import cgi The next step is to load the form data into a variable in your Python script We’ll do this using the cgi.FieldStorage() function and assign it to some variable we create –Ex. form = cgi.FieldStorage()

What’s in the “form” Variable? The form variable will have all of the information stored in our HTML form Now we have to have a way to access the individual parts Each of our controls has a name attribute and a unique name –This is how we are going to access the values in each part of the form

Accessing the Information When we want the value entered into a specific control, we have to know the name we gave it in the HTML The method of accessing its value is: form[“name”].value –form is the name of the variable we assigned cgi.FieldStorage to (form = cgi.FieldStorage) –“name” is the value of name attribute in the HTML of the control –.value gives us the value for that control

Information Access, cont. If you specify a name that doesn’t exist in your form, you will get a Key Error when you press your submit button The square brackets in the form[“name”].value are used for accessing what’s called a dictionary We are looking up in the dictionary called form the entry for “name” –Each item in the dictionary will have a value associated with it

Using Values from a Form We can use the values from the form like we would any value returned by a function One thing to do is to assign it to a variable so that we can easily reuse it –customerName = form[“custName”].value –phoneNumber = int(form[“custPhone”].value All of the data stored in form will be a string –If we want a number, we have to convert it using the (int) or (float) functions

Calling the CGI Script The tag seems like it does nothing –But remember that it has to have the action attribute When the user presses the “submit” button on the form, the script specified in the action attribute is called and can access the information stored in our HTML form Remember that the action attribute specifies the URL of the script we want to call

Basics for a Form To add a form to our website requires two things: –The HTML form Some controls Submit Button –The Python script to do something with that information Why ask for the information if we don’t do something with it?

In-Class Example Creating a simple form Using a Python script to output a new web page

Questions? We’ll be covering this more in-depth on Friday when we have internet access and we can actually see a demo