|
home—lects—hws
D2L—breeze (snow day)
Due 2015.Feb.20 (Fri) 11:00, on D2L dropbox, and accessible online.
No hardcopy.
Update:
By Fri 11:00, on D2L only:
a form with one text input-field,
and a form-handler which prints out what had been entered into the form, suitably sanitized.
The full hw03 is due 2015.Feb.23 (Mon) 11:00.
You are working for TriviaQwack, makers of a popular mobile game. They don't come up with their own trivia questions; instead they have users submit trivia questions (or “TQ”s as they say in the biz). You have been hired to create a web-page for letting people enter new questions. When they submit their form, they will see a response page summarizing the information they entered.
An example of filling out the form | The result of the processing the form |
For this homework:
Make a web-form at
https://php.radford.edu/~yourUserName/itec325/hw03/tq-edit-form.php
(and keep all hw03 files together in this
When printing values taken from the form, sanitize the HTML (that is, convert raw-text into equivalent html-text). A user should be able to enter (say) a description which includes characters like < and ' and newlines, and the resulting summary should show the same string as whas was entered, up to whitespace. (However, do show linebreaks, in the question and the answer.)
You don't need to validate the form-data, though: you can assume the weight is a number in the indicated range, that at least one checkbox is checked, etc.
Note that the checkboxes for the category should all have the same name attribute (and it should end in “[]”), so that you can retrieve it as an array in your form.
The three files should initialize it to: (0) an empty array; (1) an array with the “routine” values all shown in the example; and (2) an array where every field includes a value that an attacker might use. Your resulting page doesn't have to identify these problems, but it should not cause any errors or allow any html-injection. In particular, if an input field contains (say) an ampersand, then the resulting page should display the ampersand as typed.
A function
We will see in class this week,
how to use
You are free to refine this function.
For example,
You may optionally define a constant1 (say)
“
This function only prints (doesn't return anything); no tests are needed for it.
Write a function
For example, calling
You'll probably want to write a sample series of checkboxes by hand,
to serve as your test cases' expected-output.
Use label tags to group each checkbox with its adjacent text.
Hint: make a test case or two, first! This gets you thinking about what desired html you want to create, as well as what other arguments might be needed.
It's fine to have the buttons arranged differently than the screenshot (in particular: they can be in a long line/list).
A function
No test cases required — this function prints, and does not return anything.
The function
No test cases required. You may have this function print, or (if you prefer) return a string.
Use
Hint:Someif -else statements are acceptable, but if you want to show off your skillz, tryarray-diff
I will visit the URL https://php.radford.edu/~yourUserName/itec325/hw03/index.php to grade your work. If that URL is not accessible, you will get a 0 for that portion of the grading!
Please run/check your program/html incrementally — don't write huge amounts of the assignment w/o even running it.
1
See
2the function to show-source a file is one of the few exceptions ↩
home—lects—hws
D2L—breeze (snow day)
©2014, Ian Barland, Radford University Last modified 2015.Feb.18 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |