Form Data (part 1) MIS 3502, Fall 2015 Brad Greenwood, PhD Department of MIS Fox School of Business Temple University 11/10/2015
MySQL Weeks 6 & 7 HTML & CSS Weeks 1 & 2 PHP Weeks 3 – 5 PDO Week 8 & 9 Course Overview 2 To do: Organize your code with MVC (week 11) Work with forms (week 12) Use cookies and sessions (week 13) We are here.
Objectives (this class and next) © 2014, Mike Murach & Associates, Inc. Slide 3 1.Use text boxes, password boxes, radio buttons, check boxes, drop-down lists, list boxes, and text areas to get input from the user. 2.Use hidden fields to pass data to the web application when a form is submitted. 3.Use the htmlspecialchars and nl2br functions to display user entries the way you want them displayed. 4.Get this data in to (and out of) a database table
Warm up – some things we’ve seen before… © 2014, Mike Murach & Associates, Inc. Slide 4
© 2010, Mike Murach & Associates, Inc. Slide 5 Murach's PHP and MySQL, C7
© 2010, Mike Murach & Associates, Inc. Slide 6 Murach's PHP and MySQL, C7
Radio buttons © 2014, Mike Murach & Associates, Inc. Slide 7
© 2010, Mike Murach & Associates, Inc. Slide 8 Murach's PHP and MySQL, C7 Notice how the name ‘card_type’ has been used here. The same name was used three times. Why?? When we have a collection of form elements that are logically grouped together, we may used a tag. Putting the input tags inside of does this and results in forms that are more intuitive to use.
© 2010, Mike Murach & Associates, Inc. Slide 9 Murach's PHP and MySQL, C7
Check Boxes © 2014, Mike Murach & Associates, Inc. Slide 10
© 2010, Mike Murach & Associates, Inc. Slide 11 Murach's PHP and MySQL, C7 Notice that here, the names are different. We need a way of distinguishing one next box from another. Next class, we’ll look at an alternate approach to dealing with multiple check boxes…c
Text Areas © 2014, Mike Murach & Associates, Inc. 12 Hear ye, Hear ye …
© 2010, Mike Murach & Associates, Inc. Slide 13 Murach's PHP and MySQL, C7 Note the use of “rows” and “cols” here.
© 2010, Mike Murach & Associates, Inc. Slide 14 Murach's PHP and MySQL, C7
© 2010, Mike Murach & Associates, Inc. Slide 15 Murach's PHP and MySQL, C7 Free text input is unpredictable! It is advisable to clear it up with the htmlspecialchars function.
nl2br © 2010, Mike Murach & Associates, Inc. Slide 16 Murach's PHP and MySQL, C7 Users are also prone to put line breaks (that is, carriage returns) in text areas. If you want to translate those line breaks to HTML break tags… PHP has a function for that exact purpose. The name nl2br means…. New Line 2 Break. Isn’t that way 2 cool?
© 2010, Mike Murach & Associates, Inc. Slide 17 Murach's PHP and MySQL, C7
Game Time… © 2014, Mike Murach & Associates, Inc. Slide 18