Slide 1

Slide 1 text

PHP 101+1:function & form Fundamental PHP & Web Development lecturer : Lucien Lee 李柏緯 Lecture 3

Slide 2

Slide 2 text

? What is function 2

Slide 3

Slide 3 text

function 3 give input and send back output

Slide 4

Slide 4 text

4 function IN out

Slide 5

Slide 5 text

5 feature function IN out

Slide 6

Slide 6 text

function 6 function Name([arguments]){ statements; return output; }

Slide 7

Slide 7 text

function example function discount($price){ $price *= 0.8; return $price; } 7

Slide 8

Slide 8 text

use function $item1 = 1000; echo discount($item1); ---Another place--- $item2 = 800; echo discount($item2); 8

Slide 9

Slide 9 text

variable scope 9 Does the variable still alive?

Slide 10

Slide 10 text

Scope 10 $Julia $global function A $Liz function B $global $Julia $global $Liz $global

Slide 11

Slide 11 text

Scope $A = “hello”; echo $A; //”hello” function inner(){ $A = “world”; echo $A; //”world” } 11

Slide 12

Slide 12 text

some function 12 introduce some php function

Slide 13

Slide 13 text

isset() Determine if a variable is set and is NULL. 13

Slide 14

Slide 14 text

empty() Determine whether a variable is empty 14

Slide 15

Slide 15 text

time() number of seconds since the Unix Epoch 15

Slide 16

Slide 16 text

date($format) return date info with format 16

Slide 17

Slide 17 text

rand([min,max]) get random value 17

Slide 18

Slide 18 text

array_search(value,array) find value exist in array or not 18

Slide 19

Slide 19 text

! form: basic way pass info to back 19

Slide 20

Slide 20 text

form 20 from wikipedia

Slide 21

Slide 21 text

form input element 21

Slide 22

Slide 22 text

from 22 •action: Specifies where to send the form-data when a form is submitted. •method: Specifies the HTTP method to use when sending form-data. •name:Specifies the name of a form.

Slide 23

Slide 23 text

Text Fields 23 from w3schools

Slide 24

Slide 24 text

Password Field 24 from w3schools

Slide 25

Slide 25 text

Radio Buttons 25 from w3schools

Slide 26

Slide 26 text

Checkboxes 26 from w3schools

Slide 27

Slide 27 text

textarea At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies. 27 from w3schools

Slide 28

Slide 28 text

select Volvo Saab Mercedes Audi 28 from w3schools

Slide 29

Slide 29 text

Button Click Me! 29

Slide 30

Slide 30 text

Submit Button 30

Slide 31

Slide 31 text

? GET & POST 31

Slide 32

Slide 32 text

HTTP method 32 request and tell server what to do

Slide 33

Slide 33 text

GET •Retrieve data •remain in the browser history •never be used when dealing with sensitive data •have length restrictions 33

Slide 34

Slide 34 text

POST •query sent in HTTP message body •do not remain in the browser history •no restrictions on data length •(as create in RESTful) 34

Slide 35

Slide 35 text

35 GET POST

Slide 36

Slide 36 text

more method •HEAD •PUT •DELETE •TRACE •CONNECT •...... 36

Slide 37

Slide 37 text

? How to retrieve message in server 37

Slide 38

Slide 38 text

IN SERVER 38 •$_GET[‘name’] •$_POST[‘name’]

Slide 39

Slide 39 text

Live Coding 39

Slide 40

Slide 40 text

HomeWork 40 • make a drink order form and when user confirm, calculate the total money. • if amount of drinks is greater than 10, all drinks have 10% discount. • ceiling the final price.

Slide 41

Slide 41 text

Test Data 41

Slide 42

Slide 42 text

HomeWork Advanced 42 • make a drink order form and when user confirm, calculate the total money. • ordering black tea and green tea together has 20% discount. • expect drinks with above-mentioned discount, if amount of drinks is greater than 10, these drinks have 10% discount.

Slide 43

Slide 43 text

Test Data 43