RU beehive logo ITEC dept promo banner
ITEC 325
2017spring
ibarland

homelectshws
D2Lbreeze (snow day)

server-side-validation
Server-side validation

Due: Part (a) 2017.Mar.03 (Fri) 23:59 on D2L only;
The full homework: Mar.14 (Tue) at class time16 14:00 (Thu) Submit files on D2L, and have them online at php.radford.edu/~yourUserName/hw05/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.
(You may use parts of the hw03 solution, as long as you cite it of course.)

You should have a page https://php.radford.edu/~yourUserId/itec325/hw05/index.php which contains a link to: (i) this homework page, (ii) your okaymon-form.php, and (iii) your okaymon-handle-test-i.php files. Be sure to use the names specified here. Presumably, you will want to start by copying your hw03/ directory to a new hw05/ (via cp -r ).

Server-side validation

(6pts) As before, after submitting okaymon-form.php 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 “okaymon-handle-test-N.php” pages: one which has only a single invalid input, and one which has all inputs invalid (including the weight-units and energy-type). Keep in mind that if an input-field has multiple ways to be invalid, you should be confident your form catches the error — e.g. a species which exceeds the max-length, and another with no letter-character.

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:

1The species-name may have to appear on the top of a playing-card, so we limit its length rather strictly.      
2 I recommend an array of max-lengths, which map the name-attribute to the length: array( 'trainerName' => 80, ).      
3Remember 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)


©2017, Ian Barland, Radford University
Last modified 2017.Mar.07 (Tue)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.