Download presentation
Presentation is loading. Please wait.
Published byDouglas Bell Modified over 9 years ago
1
ITM 352 - © Port, Kazman1 ITM 352 HTML Forms, Basic Form Processing
2
ITM 352 - © Port, Kazman2 Some Inspiration! Perseverance: never giving up Indomitable Spirit: never wanting to give up Formula for success Perseverance + Indomitable Spirit = Success Indomitable Spirit “Get to your limit and see what’s on the other side” - Yoga "Try not. Do, or do not. There is no try." - Yoda “Suffering is optional” – Yoghurt “If you’re brain is hurting it just means you’re learning” – P 2
3
ITM 352 - © Port, Kazman3 What We Will Cover Today Today we will explore HTML forms in some detail: Details on Input types Compound types Some tips for HTML form elements
4
ITM 352 - © Port, Kazman4 Form Parts action is the file you want to go to (could be html or php) method should be either POST or GET
5
ITM 352 - © Port, Kazman5 Action An action should be a URI (e.g. a file name in the current folder) or a full web address, e.g. http://www.somewebserver.com/myfile.php) Example: … This will take the user to the invoice.php page in the current directory when the user presses the submit button. Note: You should always use quotes around the URI in case it has special characters or spaces.
6
ITM 352 - © Port, Kazman6 Method The method can be either 'POST' or 'GET'. $_GET and $_POST are arrays built into PHP which make form processing a lot easier. Form variables are stored as keys (elements) of these arrays, indexed by their name To see what is in the array just do a var_dump() e.g. var_dump($_GET); TIP: put var_dump() at the top of form processing files so you can see what is sent from the form
7
ITM 352 - © Port, Kazman7 Submit Button Usually you need to have a submit button to invoke a form's action, e.g.: <input type = 'SUBMIT' name = ' the name you want to appear in the POST/GET array ' value = ' the label in the button ' >
8
ITM 352 - © Port, Kazman8 Example: Login Do Lab #1
9
ITM 352 - © Port, Kazman9 Input types (single value) A generic input type looks like this: ' name = ' ' value = ' ' >
10
ITM 352 - © Port, Kazman10 The Basic Input Types Text Password Hidden Radio Checkbox Submit
11
ITM 352 - © Port, Kazman11 Login <?php print "logged in ". $_POST['username']; ?> Do Lab #2
12
ITM 352 - © Port, Kazman12 Self-Processing Form Sometimes you want to stay on the same page when processing your forms ' method = 'post'> is the same as: 'method = 'post'> <?= is short for echo when embedding PHP in HTML You can use $PHP_SELF or $_SERVER['PHP_SELF']
13
ITM 352 - © Port, Kazman13 Login if( array_key_exists('submit_button', $_POST) ) { print "logged in ". $_POST['username']; } else { ?> ' method = 'post'> Do Lab #3
14
ITM 352 - © Port, Kazman14 GET method … GET will show the information being passed between pages as part of the URL. Good tool for error checking However, it is not secure because users can see the full contents of the request. Pages can be cached.
15
ITM 352 - © Port, Kazman15 POST method … POST will hide information being passed between pages in the address bar. HINT: use GET for error checking; change to POST when submitting your work More secure than GET Pages won't be cached. Do Lab #4
16
ITM 352 - © Port, Kazman16 Compound Types Select Text area List box Compound types enable multiple inputs and/or outputs Unlike input types, compound types always use a begin and end tag …
17
ITM 352 - © Port, Kazman17 Login if( array_key_exists('submit_button', $_POST) ) { print "logged in ". $_POST['username']; } else { ?> ' method = 'post'> Moe Larry Curly <input type = 'submit' name = 'submit_button' value = 'login'>
18
ITM 352 - © Port, Kazman18 Select Boxes Select boxes provide a drop down set of options for the user to choose from. Value is whatever the user chooses when the submit button is pressed If no value parameter is set, the value defaults to the label thing1 thing2 thing3
19
ITM 352 - © Port, Kazman19 Text Area Text Area provide a region of size row X cols to display and input text. Value is whatever is in the area when the submit button is pressed This is some text in the text area.
20
ITM 352 - © Port, Kazman20 Tips and Hints Use single ' ' on the inside, " " around the outside or vice versa Take advantage of PHP by using for/while/foreach to generate multiple form elements and compound types Quotes must be used around anything with spaces Do Extra Credit (optional)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.