Purpose To practice a few elements from chapters 1-3; embedding PHP, using form elements to send information, retrieving and using form information, loops and control structures, and writing text files.
The assignment: Time to buy some groceries! You and your roommates are so busy that it's hard to coordinate everyone's wants when it comes time to refilling the 'fridge, and besides, you can't read their poorly written grocery lists when it's your turn to do the shopping. So, you are going to make a computer grocery list to make it simpler.
You are to create a shopping list with a least three groups of foods (dairy, veggies, snacks, deserts, fruits, and meats, perhaps?) and at least 5 items in each group. For each item, create a form with the item name, a check box indicating that it should be on the list (initially, unchecked), and a text box for quantities. Specify the unit with the food (e.g., apples, bag; milk, quart) so that you don't have to specify that now. And don't worry about the price for now. The form should be an alphabetical listing by item, ignoring grouping.
The form will call a page that will create a shopping list. Because items in a grocery store are generally located in groups, you are to list the groups (but only if there are any items in them) and present an alphabetized listing of items and quantities (e.g., milk, quarts—4).
The action in your form should call the same page that contains the form. That is, your second page is actually on the same page as the form itself. Append a name and value pair to the action page's URL; this should be "read" by the page and depending on the value, you should use a switch structure to take you to the form results part of your page. (See the basic structure at the end of the chapter 1 notes.
Finally, make sure that your list is both displayed on the screen and also written to a text file so that we can print it out to take to Stop and Shop.
Grading: This assignment is worth 5 points. Each of the following are required; each is worth 1 point. One point will be deducted if the assignment is not done by the due date.
- 1—HTML form with all elements working correctly to send information.
- 2—PHP page able to read form values
- 3—a single PHP page with both form and results, with a branching structure to move to either the form or the results
- 4—form output arranged by group (above), and alphabetically within groups
- 5—Well-constructed html and php with php liberally commented throughout.
Schedule: Assigned 1/29 | due 2/6.