Section 4 Sp 11
From CSE190M-Admin
Contents |
[edit] Links
- Writeup -- Section 4
- New section handout (in development)
- Complaint Skeleton -- complaint.html
- Letter Skeleton -- letter.php
- Sentences -- sentence.txt
- Example solution -- complaint.html
- Example solution -- letter.php
.
[edit] Rough Outline
This section is about practicing more PHP, especially with HTML forms.
Forms-related problems:
- Buggy HTML form
- Animal Gallery (optional second part)
- Login
- Caption
- Complaint Letter Generator
PHP submission-handling problems:
- Animal Gallery (query string)
- Login
- Caption
- Complaint Letter Generator
PHP-only practice problems:
- Show Twos (functions)
- Calculations
[edit] Buggy HTML form
This problem could be good to do as a group refresher. It's got several bugs in it, including stylistically poor choices:
- Doesn't submit anywhere (submit it to params.php on Webster)
- First input tag is missing a name attribute
- 'year' checkboxes should be radio buttons w/ values
- label tag wraps up many checkboxes
- studentid box should have maxlength set, not just size
- Personal statement should be a textarea
[edit] Animal Gallery
The goal of this problem is to practice file globbing on the server and reading query parameters. Feel free to compose a client-side form to submit to the script if you want.
[edit] Login, Caption
These are simple two-part client- and server-side form problems. They have some extra features to add if you have time.
Login is meant as an example of a form which should be submitted using POST (due to the password element), so it's a good opportunity to rehash the differences between GET and POST.
[edit] Show Twos, Calculations
These are meant to be practice writing functions and producing output. Calculations reads from a file on the server and parses it to produce some HTML output; Show Twos is a function with a parameter which produces some HTML output.
[edit] Complaint Letter Generator
- Make sure you have saved the Skeleton pages and sentence.txt ahead of time
- It can be a great example of what not to do, especially style-wise and common mistakes (ie. forgetting the add the "name" attribute)
- Be sure to work in steps, pointing parameters to http://webster.cs.washington.edu/params.php
- Once your form submits properly, write a PHP page letter.php on the server to process this form data. Start from the skeleton
- Show them the contents of sentence.txt, noting the placeholders like _FNAME_
- When showing them how to use str_replace, first use it to replace _FNAME_ then a separate statement to replace any _LNAM_ and so on in that line, working your way towards the redundancy. Then show them the arrayFrom --> arrayTo, replacing array items in a given string.
- If you write the code correctly, you can do this with a single call.
- After you finish and there is still time, try validating the form with some basic server-side validation. Maybe show them how to use the forum CSS selectors, or add a feature like a "Custom Complaint!"