LIS651 lecture 0 PHP introduction, HTML form, shop Thomas Krichel 2005-03-12.

Slides:



Advertisements
Similar presentations
LIS651 lecture 0 Gathering and showing data Thomas Krichel
Advertisements

LIS651 lecture 0 Gathering and showing data Thomas Krichel
LIS651 lecture 0 forms Thomas Krichel
HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
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?
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.
24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
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
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.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
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.
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.
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?
Lesson 13: Building Web Forms Introduction to Adobe Dreamweaver CS6 Adobe Certified Associate: Web Communication using Adobe Dreamweaver CS6.
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.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Website Development with PHP and MySQL Saving Data.
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) HTML Forms James Wang.
HTML Forms.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
ITCS373: Internet Technology Lecture 5: More HTML.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
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.
LIS651 lecture 0 collecting and showing data Thomas Krichel
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.
LIS651 lecture 0 Gathering and showing data Angela Cornwell, Thomas Krichel
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
+ 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.
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.
COS 125 DAY 17. Agenda  Assignment 7 not finished grading  Assignment 8 posted Due April 9  Capstone progress reports due  Quiz 2 Corrected 2 A’s,
20-753: Fundamentals of Web Programming 1 Lecture 6: Advanced HTML Fundamentals of Web Programming Lecture 6: Advanced HTML.
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 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
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.
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.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
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.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
How to Write Web Forms By Mimi Opkins.
LIS651 lecture 0 Gathering and showing data
HTML Forms and User Input
Presentation transcript:

LIS651 lecture 0 PHP introduction, HTML form, shop Thomas Krichel

today we introduce PHP forms filling in to prepare for active web sites then we build a little shop with form and PHP.

PHP introduction PHP is the PHP hypertext processor. It is a tool that allows for server-side scripting. It is an interpreted language. –You write a series of statements. –Apache hands these statements to the PHP interpreter. –The interpreter executes these statements one by one. –When it find an error, it stops executing and signals the error. Compiled languages are different. They read the whole program before starting to execute it.

good old wotan Remember we duplicate validated.html when creating a new new file. Right-click on validated.html, choose duplicate. You may be asked to supply your password again. You erase the contents of the dialog box that suggests a new file name and put your new file name in there. If it contains PHP code, it has to end in.php.

first PHP script Create a file with the name info.php, and the following contents <?php phpinfo(); ?> nothing else. This will create a test page that tells you everything PHP knows about.

comment on info.php If a file has the ending.php, Apache does not show the file to the client as is. Instead in shows in another program, the PHP reads the file. When it finds The rest of the file is transmitted as such.

statement A PHP program contains one or more statements. Each statements tells the interpreter something. Each statement is ended by a semicolon. In our first script there is only one statement. phpinfo() is a function. That is a statement that does something to something else. The "something else" is in the parenthesis. It is called the argument of the function. In this example, it is empty. Each statement is ended with a semicolon!

output of phpinfo() phpinfo() create a whole web page for you, that validates against a loose HTML specification. That page contains a lot of technical detail. The section we may be interested in is PHP Variables. –it contains variables that we may be interested in. The client will NEVER see the PHP code that you have written.

second php script: hello.php Normally we write HTML code and then we add bits and pieces of PHP inside. Take validated.html, copy to hello.php make the body <?php print("hello world"); ?> validated the resulting HTML.

comment on hello.php print() is also a function. print prints its argument. Here the argument is a string. A string is a sequence of characters enclosed by single or double quotes. For print, the () can be omitted. You could have written three statements <?php print " "; print "Hello, world!"; print " "; ?>

good style Write each statement on a new line. Add plenty of comments. There are three styles of comments in a PHP program –// the rest of the line is a comment –# the rest of a line is a comment –/* this is a comment */ The last style can be used over several lines. It is familiar from CSS.

another way to write hello.php <?php $greeting="Hello, world!"; print " $greeting "; ?> Here $greeting is a variable. The first statement assigns it the string value "Hello, word!". The second statement prints it out. This example is important because it illustrates the concept of a variable. The name of the variable is greeting.

Forms Forms are parts of an HTML document that a user can fill in. The thing that users act on are called the controls of the form. They include buttons, checkboxes, text areas, file selections... Some controls are hidden. Controls are submitted to PHP in the form of variables. Each control in the HTML form becomes a variable in PHP.

forms examples Here is an example in forms Elements used in forms use a special attribute group that I will call the "form attributes". I will discuss them now.

form attribute: tabindex= Stupid users use the mouse to fill in form. Smart users use the tab character on the keyboard. It is much quicker. if you set the tabindex= on a in input, you can set the order. The value of the attribute is a number between 0 and The input with a lower number will be dealt with before the one with a higher number.

form attribute: readonly= If you set readonly="1" the control can only be read but not set. readonly="0" is the default, it means that the control can be set. if an input is readonly="1" –it can receive focus but cannot be modified by the user. –it is included in tabbing navigation. –it is transmitted to the server for processing

form attribute: disabled= If you set disabled="1" the control can only be read but not set. disabled="0" is the default, it means that the control can be set. if an input is disabled="1" –it can not receive focus and can not be modified –it is excluded in tabbing –it is not transmitted to the server for processing.

This element encloses a form. It accepts the core and i18n attributes. It admits a method= attribute. This attribute determines the http method by which the form is submitted to the script. There are only two choices –GET –POST

method="GET" If you use GET, the form data is transmitted by appending it to the URL of the script. Google's Web search does it that way. There is a standard way to write the data in the URL knows as Common Gateway Interface, CGI. It is of no further interest to us. Advantage: you can bookmark the form. Problem: there is a limit of 1024 chars for the URL, therefore only a limited information can be transmitted in this way.

method="POST" if you use post, the user agent sends the form as a POST message to the server. The data is sent in the body of the http exchange. Thus it can be as long as you want. If you use POST you can set the content-type of the message with a special attribute enctype=

more attributes to Here are two more attributes I will list for completeness –accept-charset= says what character sets will be accepted by the form –accept= says what MIME-types can be accepted.

This element creates a control. Usually a form has several s as well as text that explains the from. Note the emptiness of the element. It admits the core, i18n and the from attributes.

the type= attribute of This attribute can only take the following values –textenter text –password enter text, but don't echo on screen –checkboxenter checks on boxes –radiocheck one select –submitpress to submit form –resetreset form –fileupload file (can only be done with POST) –hiddenhidden form data, not shown –imageimage map submission, not covered further –button a button

the name= attribute of This give a name to the control that the users are setting. The script that is found by the action= attribute will identify the controls by name. Therefore every control should have a different name.

control name and PHP variable When the form is passed to the PHP script named with the action= attribute of the the form, the controls are accessible as PHP variables. If name is the name of the control, and if the method is POST, the control is read as the variable $_POST['name']. If name is the name of the control, and if the method is GET, the control is read as the variable $_GET['name'].

example HTML file greet.html has your last name: PHP file greet.php has <?php $last_name=$_GET['lastname']; $greeting="Hello"; $title="Mr or Ms"; print "$greeting $title $last_name"; ?>

the size= attribute of It lets you set the initial size of the input field. When the type is 'text' or 'password' the value you give to this field is the number of characters. Otherwise it is the number of pixels.

the maxlength= attribute of this sets the maximum length on the value. note that this is different from the size of the input field because there is scrolling. if you don't specify a maximum length there is no limit.

the value= attribute of This gives the initial value of the. The initial value is shown to the user, and sh value= is optional but should be given for the radio and checkbox type.

other attributes of When the input is of type 'radio', setting the checked= attribute to any value will tell the browser what button is initially set. Of course there can only be one of them. When the input is of type 'checkbox', setting the checked= attribute to any value will make sure it is checked initially. When the input is of type 'image' the src= attribute gives the URL of the image. This is for image maps.

the element This makes a button for decoration. It takes a type= attribute that can be either be 'button', 'submit' or 'reset'. It has takes a name= attribute for the name of the control that it sets. It takes a value= attribute attribute to set a value. It also takes the core and i18n attributes. And it can have character contents!

creating menus This is done with element. Each element can have a number of elements that contain the options that the user can choose from.

attributes to multiple="1" allows and multiple="0" (default) disallow multiple selections. size= sets how many rows of the selection should be displayed at any one time. name= has the name of the control that is set. It also takes the core and i18n attributes.

attributes to value= can be used to set the value of the control when the value set is different than the contents string of the option element. label= can be set to label the option. if it is set, the user agent should use label rather than the content. At least this is what the spec says. Firefox does not seem to agree. takes the core and i18n attributes.

This element has elements as its children. It is used to create hierarchical options. This is mainly a time and space-saving device in the presence of many options. Say takes the same attributes as.

the element This creates a text area where you can put a large chunk of text. name= sets the name of the control that is set. cols= sets the number of columns in the text area. rows= sets the number of rows in the text area. also admits the i18n, core and form attributes.

This is a way to add labels for inputs. Normally, the input label should be taken from the label= attribute of the input. can be used if the other method can not be. It accepts a for= attribute to give the input for which it is the label is for. Example: your sex

summary forms deliver data to the server. The server can then process the data and deliver a response. Active effects can also be done client-side. This is done using the element that mostly uses a language called javascript.

complete example: shop We build a form, that allows people to buy things in a shop. The result of the form is the itemized bill, including totals with sales tax! Each of you will build a shop now. Each will choose a shop on a different topic. When you are done, you can go home. You will not go home until you are done!

saar_bier.html, part 1 Grosswald Brauerei (since 1860)

saar_bier.html, part 2 Brauerei Bruch (since 1702)

saar_bier.html, part 3

saar_bier.php, part 1 <?php $gross_pils=$_POST['gw_pils']; $p_gross_pils=$_POST['p_gw_pils']; $t_gross_pils=$p_gross_pils*$gross_pils; $gross_expo=$_POST['gw_expo']; $p_gross_expo=$_POST['p_gw_expo']; $t_gross_expo=$p_gross_expo*$gross_expo; $bruch_land=$_POST['bruch_land']; $p_bruch_land=$_POST['p_bruch_land']; $t_bruch_land=$p_bruch_land*$bruch_land;

saar_bier.php, part 2 // add up the grand total in euros // note how this statement stretches several lines $total_euro=$t_gross_pils +$t_gross_expo +$t_bruch_land; // get the euro rate from the form $euro_rate=$_POST['euro_rate']; // calculate the total dollars $total_dollar=$total_euro*$euro_rate;

saar_bier.php, part 3 print " You ordered "; print " $gross_pils bottles of Grosswald Pils, cost $t_gross_pils "; print " $gross_expo bottles of Grosswald Export, cost $t_gross_expo "; print " $bruch_land bottles of Bruch Landbock, cost $t_bruch_land "; print "Your bill is $total_dollar US dollars. "; print "We ship when we get your check! "; print "Prosit! "; ?>

Thank you for your attention! Please switch off computers when you are done!