RU beehive logo ITEC dept promo banner
ITEC 325
2020fall
ibarland

form-handling
and html sanitizing

Part (A) Due Sep.15 (Tue.) 23:59 (in D2L and accessible online).

You have been hired to help develop the game Okaymon -- a crowdsourced game of evolving monsters! You need to develop a web form with the information below; when the form is submitted, the user is shown a page which simply re-caps the submitted information.

example okaymon-info form screenshot example okaymon-info form screenshot

Part A

  1. (10pts) dropdown : string, string[] → string, which produces the html for a drop-down menu. (To think about: the array is what to have as the options for the drop-down. What is the string for? This will be clearer after you make a test case for a usable drop-down.) Note that half the points are for having good tests, on this problem and others.

    Then, modify your function to include an additional, optional input, of type boolean-or-string: A true indicates to include “select one” as the first entry in the drop-down; it wouldn't correspond to a meaningful choice. Providing a string is similar, except that instead of the words “select one”, use the provided string. Finally, false indicates to not include any such item. The default value should be true, if it's not explicitly passed in.

  2. Make the form and form-handler as shown, but without the table of radio-buttons, for now. Name your files okaymon-form.php and okaymon-handle.php.
    Your forms don't need to look exactly like the above1, but should have the same information (and look respectable).

  3. Part B

  4. In class, we wrote part of radioTable. We'll complete that here.
    1. We will want the all the inputs to get grouped together into a single array, contained inside $_POST. For example, if a radio table lets you enter information about whether fifty different foods are yucky, meh, or yummy, we'd want something like

      $_POST["food-tastes"] === array( "Snickers" => "yummy", "Bananas" => "meh",  )
      $_POST["food-tastes"]["Snickers"] === "yummy"
                 
      You'll need to think what input-names you'd want, to be able to create this.

    2. (10pts) Write radioTableRow : string, string[] → string which produces a bank of radio-buttons inside of a table-row. For example, radioTableRow( "clover", array("weak-to","neutral","resistant") ) would return the first row of the table in the screenshot below. (The name attribute of buttons in that row would be “clover”.) Note that this function does not return an entire table, just a single table-row (tr).
      Hint: For full credit, call one of your functions from the previous homework solution, as a helper!
      Extra credit: (2pts) Include a parameter for naming the entire table, used to group the results. Grouping the entire table's inputs into a single array is certainly the proper data-representation; the actual lecture-notes on how to do this are on the schedule for the lecture before this hw is due: grouping web-inputs into arrays.
    3. (4pts) As we wrote (part of) together in lecture, write radioTable : string, string[], string[] → string which returns the html for a table of radio-buttons (including the column-headers, taken from the first array). This function will naturally call radioTableRow. You must have test-cases for it.

      Using name-attributes with square-brackets, the results from each row should be grouped together in an array, in $_POST.

  5. Now include the radio-table in your form. The form-handler should print out all the energy strength/weaknesses by looping over the array of energies.
  6. Make a separate file of constants, e.g. the array of energy-types. Your form and form-handler can both require_once the constants-file.
  7. In order to test your form, you must also have three files “okaymon-handle-test-N.php” (for N = 0,1,2) which populate $_POST with (respectively): (0) no information, (1) typical inputs, and (2) input where each input includes characters like “>” or “'” or “\n”.

Deliverables

This assignment is spread across several files: utils.php, utils-test.php, the form okaymon.php, the form-handler okaymon-handle.php, and (for part (B)) at least three “okaymon-handle-test-N.php” files and a constants-file defining the array of energy-types.

For part (A) just submit the required files to D2L; for part (B) both submit on D2L and bring hardcopy to class.

Your form must be viewable on-line at https://itec-php01.radford.edu/~yourUserID/itec325/hw03/okaymon-form.php.


1 In particular, you don't need to have an apostrophe when mentioning thinkin’ energy.      

logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.