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

homelectshws
D2Lbreeze (snow day)

server-side-validation
Server-side validation

Due: Part (a) 2016.Oct.17 (Mon) 23:59 on D2L only;
The full homework: Oct.19 (Wed) 11:00, D2L and forms available at php.radford.edu/~yourUserName/hw04/index.php. (No hardcopy needed.)
For part (a), include:


We will incrementally improve on hw03—hw03: form-handling: and html sanitizing's Okaymon page by adding server-side validation.

Your should have a page https://php.radford.edu/~yourUserId/itec325/hw04/index.php which contains a link to your okaymon form (and, to this homework) near the top, and include a list all your files (with links). (That is, a link to each of your handler-sample files, and a link to your css file, etc.. Hint: scandir.) Presumably, you will want to start by copying your hw03/ directory to a new hw04/ (cp -r ).

Server-side validation

(6pts) As before, after submitting the okaymon-form will lead to a page which prints the received information. However, the page's title (and, its headline) should be either something like “okaymon info submitted” (as before) or something like “okaymon form contained n errors”. Then, if there were errors, give a list of the error-messages before printing the received-information. Error message should be specific: e.g. rather than saying a field is “either required or too long”, just report the true problem.

What to validate

The following properties should hold (and you should report a validation-error-message if they don't):

(6pts) You must have a function allErrorMessages which (as we'll discuss in class) takes an array of form-info, and returns an array of error-messages. Your test-cases for this might simply test that the returned array has the expected number of messages, w/o checking the exact text of the messages. Have helper functions for general-purpose/re-usable tasks, as appropriate (e.g. a function rangeErrorMessage : string, number, number → string-or-false which makes sure an input is a number in the expected range (returning an error-message if it's not, or just false if it is in the range).

Include unit-tests for each function you write, of course. Also, add at least two more “form-sample” pages: one which has only one invalid input, and one which has all inputs invalid (including the weight-units and energy-type).

You might want to start by creating another sample-page which includes some of the wacky things to check for: an entry which is nothing but spaces; an entry claiming the that the dropdown-item “easy-peasey-lemon-squeezy” was selected (even though your dropdown has no such option), etc.. This will help focus your thoughts about what you need to check, when validating.

Structure of code


Other requirements

These apply to all homeworks for this class:

1Admittedly, having a link to your utils.php isn't very interesting, because I won't see its contents, but only what it prints. Still, if it's easy to have a link to it (via a loop), then it shouldn't be a problem.      

2The species-name may have to appear on the top of a playing-card, so we limit its length rather strictly.      

3 I recommend an array of max-lengths, which map the name-attribute to the length: array( 'trainerName' => 80, ).      

4Remember that a good CSS style-name describes the meaning (semantics) of the style, not the particular styling it creates: something like “menu-item” or “telephone-number”, or “default-entry”, and not “centered” or “bold-sans-serif” or “blue-italics”. Here is further discussion.      

homelectshws
D2Lbreeze (snow day)


©2016, Ian Barland, Radford University
Last modified 2016.Oct.12 (Wed)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.