
1301f9ae0428500bf269337bef4cf5d3.ppt
- Количество слайдов: 19
Media Software Design DIG 3134 – Lecture 3 Forms Michael Moshell University of Central Florida 1
The Objective: • Learn how to build forms, and how to capture the data from a form with a PHP program. 2
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 3
How do you make a form? Dreamweaver can do it, but you MUST understand the HTML code. You can program input fields (“controls”) directly.
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.
ex 1 form. html How do you catch the data?
"; $button=$_POST['dowhat']; print "The button clicked= '$button'. "; ? > $_POST is a built-in global array. 6
Analyzing the Data Flow Client (Browser) url: ex 1 form. html Fill in The form Render HTML, See the Results. End of story url: ex 1 capture. php Server (Apache) Send back ex 1 form. html Run the script ex 1 capture. php send back HTML: ”The dude’s. . " 7
Example 2: Combine Form & Capture Ex 2 formcapture. php From here on down, please examine the Text file “example 1. formprocessing. txt” To see the code. It’s too messy to paste it into Powerpoint. 8
The other Examples: What they show Ex 3: How to make the program replay 9
The other Examples: What they show Ex 3: How to make the program replay Ex 4: 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. 10
The other Examples: What they show Ex 3: How to make the program replay Ex 4: 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. Ex 5: No Thanks. (if – else if) 11
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 “
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! 13
Example 6: Two Inputs Ex 6. lolly. php www. realtown. com How much is that Lollipop? php # Part 1: Producing the Form: print "
Check here if you are a Senior Citizen
”; 14
Example 6: Two Inputs Ex 6. lolly. php www. realtown. com How much is that Lollipop? # PART 2: Input Processor $sale 1=$_POST['sale 1']; $seniorcitizen=$_POST['seniorcitizen']; if ($sale 1) { 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.
'; } 15
Homework 2: Numeric Input www. realtown. com Selling lots of pops Modify the Ex 6 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. Continue If you enter 10 and check the senior box, program prints "Your lollipops will cost 50 cents. " 16