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

Client side validation

Due: 2018.Nov.07 (Wed) at start of class. Submit on D2L, and as usual have your a link to your form available at https://php.radford.edu/~yourUserId/itec325/hw06/index.php. (No hardcopy needed.)

Note: Points-possible are approximate, and may change somewhat when grading.

We will further improve on server-side-validation/’s Okaymon page by adding client-side validation. Make a copy of your directory from hw051, named hw06/. (cp -pR hw05/ hw06 will Recursively copy directories, preserving timestamps.)

  1. (15pts) Using html attributes like maxlength etc., validate all input fields using the same criteria as on the previous homework.

    Be sure to use your named-constants file, for the field-lengths. (1/3 of the points are for that.)

    Note that this interacts with our previously-written functions for generating dropdowns and radio-buttons; we now want to have those input tags include a required="required" attribute, and perhaps other attributes. There are several ways to do this, but I suggest a fairly general solution: add a(nother) argument to those functions: an array whose key/value pairs are the additional html attributes you want to have included. Good thing we already wrote a function that can help with this! By making this an optional argument whose default-value is the empty array, we are still backwards-compatible with all our previous test-cases (though you'll want to add another few test cases, to test this new functionality).

  2. (5pts) As a javascript warm-up: Make your submit-button be greyed-out (set its disabled attribute), if the Intellectual Property checkbox is not selected.
    You don't need to have any other inputs affect the submit-button this way.
  3. (10pts) We're going to add one further validation requirement: the Okaymon's weight must be less than 10,000 lbs. That is, we want to give an error if the user enters a weight of 5000kg ≈ 5000kg·2.2lbs/kg = 11,000lbs.

    Write a separate javascript function which does this: if the field is too big, it inserts the message-text into a nearby span whose id is weight-err.
    (You may write reportError yourself, or use the version in the notes (with citation of course).)

    Make sure that onsubmit of the form, you also call call the validation function for the weight; if it is too large, then the form doesn't get submitted (and the error-message is being shown).

    You do not need to have your javascript in an external file, for this homework. In fact, doing so would mean that the external-javascript-file would be generated by a php program — either on each fetch, or a “dumb” which you are sure to re-generate each time you change the your okaymon-constants.php.

  4. Optional/extra-credit: For text inputs, immediately upon being entered, your javascript can trim and collapse whitespace as in hw02. (And for even a bit more extra-credit, if this results in changing what the user typed, you can display a message politely informing the user that their information was changed/normalized. You should be able to re-use code which inserted error-messages, perhaps refactoring a bit to support error- and non-error messages.)

Other requirements

These apply to all homeworks for this class:

1 You can also use the hw05-soln (posted); just cite your source as usual.      
2 the function to show-source a file is one of the few exceptions      

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.