Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 DIG 3134 – Lecture 3 Forms Michael Moshell University of Central Florida Media Software Design.

Similar presentations


Presentation on theme: "1 DIG 3134 – Lecture 3 Forms Michael Moshell University of Central Florida Media Software Design."— Presentation transcript:

1 1 DIG 3134 – Lecture 3 Forms Michael Moshell University of Central Florida Media Software Design

2 2 The Objective: Learn how to build forms, and how to capture the data from a form with a PHP program.

3 3 What is a form? It ’ s a special HTML page that Contains one or more fields to capture data. The most common kinds of fields are: Text input boxes Checkboxes Radio Buttons SUBMIT Buttons Continue

4 4 How do you make a form? Dreamweaver can do it, but you MUST understand the HTML code. You can program input fields ( “ controls ” ) directly. The ‘ form ’ tags are simple, and necessary. Be careful: don ’ t let Dreamweaver make MORE THAN ONE set of them!

5 5 What ’ s a GET? What ’ s A POST? There are two ways for data to flow from The form to the script: “get” and “post”. We will talk about “get” later. Name Name Continue

6 6 How do you catch the data? ex1form.html ex1capture.php <?php $firstname=$_POST['firstname']; print "The dude's first name is $firstname. "; $button=$_POST['dowhat']; print "The button clicked= '$button'."; ?> $_POST is a built-in global array. Name

7 7 Analyzing the Data Flow Client (Browser) Server (Apache) url:ex1form.html Send back ex1form.html Fill in The form Run the script ex1capture.php send back HTML: ”The dude’s...." Render HTML, See the Results. End of story url:ex1capture.php

8 8 Example 2: Combine Form & Capture Ex2formcapture.php From here on down, please examine the Text file “example1.formprocessing.txt” To see the code. It’s too messy to paste it into Powerpoint.

9 9 The other Examples: What they show Ex3: How to make the program replay

10 10 The other Examples: What they show Ex3: How to make the program replay Ex4: Another way to mix HTML and PHP Advantage: you can SEE the HTML in Dreamweaver ‘design view’. Disadvantage: remembering if I’m inside or outside PHP at each point.

11 11 The other Examples: What they show Ex3: How to make the program replay Ex4: Another way to mix HTML and PHP Advantage: you can SEE the HTML in Dreamweaver ‘design view’. Disadvantage: remembering if I’m inside or outside PHP at each point. Ex5: No Thanks. (if – else if – else if)

12 12 HOMEWORK Task 0: (optional) If you have very little programming Experience, try this first: Modify Example 2 by adding this line, right below The <?php line: Print “ My First Modification! ”; Then save this modified code in your htdocs or www folder as ‘test1.php’. Then in browser: Localhost://test1.php (for mac: localhost:8888)

13 13 HOMEWORK Task 1: Modify Example 5 so that it asks for The user’s FIRST and LAST names, in 2 boxes. First Name Last Name Send the data When you enter “Jane Doe” and click on “Send the Data”, the program will display like this: Congratulations Jane Doe, you have won!

14 14 <?php # Part 1: Producing the Form: print " ”; // no action? Act on yourself (this program) Print " Luscious Lollipop = 10 cents (5 cents for Senior Citizens.) Check here if you are a Senior Citizen ”; Example 6: Two Inputs Ex6.lolly.php How much is that Lollipop? www.realtown.com

15 15 Example 6: Two Inputs Ex6.lolly.php # PART 2: Input Processor $sale1=$_POST['sale1']; $seniorcitizen=$_POST['seniorcitizen']; if ($sale1) {if ($seniorcitizen) { print 'Your lollipop will cost 5 cents. '; } else { print 'Your lollipop will cost 10 cents. ';} } else { print 'You did not buy any lollipops. '; } How much is that Lollipop? www.realtown.com

16 16 Homework 2: Numeric Input Selling lots of pops www.realtown.com Modify the Ex6 program: Replace checkbox by A textbox. How many lollipops do you want? 10 cents each (5 cents for senior citizens.) Check here if you are over 60 years old. If you enter 10 and check the senior box, program prints "Your lollipops will cost 50 cents." Continue

17 17 Homework 2: Numeric Input Selling lots of pops www.realtown.com Hint:

18 18 Challenge: Graphic Output graphical pops www.realtown.com (Optional): Modify your program so that it draws however many pops you bought.

19 19 For Thursday: www.realtown.com Get ALL homeworks done! We will be starting On Project 1, on Thursday, and you need to Be Up to Speed. Come see me for help if needed! Office hours or appointments – be proactive!


Download ppt "1 DIG 3134 – Lecture 3 Forms Michael Moshell University of Central Florida Media Software Design."

Similar presentations


Ads by Google