|
home—lects—hws
D2L—breeze (snow day)
Oct.30 (Mon) 11:00. Submit files on D2L, and have them online at php.radford.edu/~yourUserName/itec325/hw05/index.php. (No hardcopy needed.)
In addition, submit a “Part (a)” by Oct.24 (Tue) 23:59 on D2L only:
We will incrementally improve on hw03’s Okaymon page by
adding server-side validation.
You may use parts/all of the hw03-soln
and/or lecture example,
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. (You're urged to automate this, similar-but-not-exactly-to this.) Be sure to use the filenames specified here. Presumably, you will want to start by copying your hw03/ directory to a new hw05/ (via cp -r …).
The following properties should hold (and you should report a validation-error-message if they don't):
warning:Only calltrim on strings — not any sub-arrays inside$_POST ! The functionis_string can help.
(4pts) 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 “field-name is either required or too long”, report “field-name is required”, or report “field-name is too long”.
Each reported validation-error message should start with the name of the field containing the error
(probably
PHP tip: PHP, unlike most languages, has an …odd notion of “global variable”. Even if a function is defined in a context which had access to a variable, in order to use that variable inside the function you have to either look up its name inside the array$GLOBALS , or declare your intent by (re)declaring the variable asglobal inside your function.
require_once("my-constants.php"); // defines variables `$foo` and `$bar`. echo $foo; function stuff() { echo $GLOBALS['foo']; // OR global $bar; echo $bar; }
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-handler-tests catches the error — e.g. one where species which exceeds the max-length, and another where it has 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.
Any generic validation functions (which could be re-used directly for other projects)
can be put into your utils.php.
…Although, that name “utils” is starting to get a bit abused, since these aren't so much
general-purpose utility functions, as part of a suite of validation functions.
(You are encouraged, but not required, to put such generic validation functions
into a separate file yet.
The rule-of-thumb would be: Might this be code you'd want to repeat when
validating an entirely different web-form (like your project)?
No matter how you organize your code, each file of functions should have its own associated
For example, for validating the weight,
have a generic function that
compares an input-string against any two numbers.
In order to be able to return a helpful error message,
that function might also take in the field's name,
perhaps
For functions returning false-or-error-string, it's acceptable to just
test whether the result is false
(w/o worrying about the exact error-message contents).
For testing
hint: When grading, some of the automated things I'll check: one file has includes “constant” in it’s name; two files have the word “constant….php” inside them; the word “puddle” only occurs once; one file ends in “.css”.
set numConstFile = `ls * | grep onst | wc -l` set numConstFileTarget = 1 set numFilesMentionConst = `grep --files-with-matches -- -constant * | wc -l` set numFilesMentionConstTarget = 2 set numFilesMentionPuddle = `grep --files-with-matches puddle * | grep -v -- -test | grep -v -- -handle | grep -v -- -sample | w c -l` set numFilesMentionPuddleTarget = 1 set numPuddles = `grep puddle * | grep -v -- -handle | grep -v -- -test | grep -v -- -sample | wc -l` set numPuddlesTarget = 1 set numCSSFiles = `ls * | grep .css\$ | wc -l` set numCSSFilesTarget = 1
home—lects—hws
D2L—breeze (snow day)
©2017, Ian Barland, Radford University Last modified 2017.Oct.24 (Tue) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |