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

homelectsexamshws
D2Lbreeze (snow day)

sticky
sticky forms

Extra Credit: Due 2015-Apr-20 (Mon) 10:00

Modify your forms from Modify your form so that it is sticky: on validation error, you are given back the form, except that any information from $_POST is pre-filled into the form (even if it wasn't valid).

There are two overall steps to this:

Organizing the sticky form

(15pts) Recall the overall skeleton-file discussed in class:

$errMsgs = array_key_exists('form-was-submitted',$_POST) ? validateAll($_POST) : array();
  
if (!$errMsgs && array_key_exists('form-was-submitted',$_POST) {
  require('skill-handle.php');
  }
else {
  // this file also prints any $errMsgs:
  require('print-tq-edit-form.php');
  }
This assumes that:

Sticky html

I recommend completing this part in the following order: first get the sticky text-fields to work (15pts), then the sticky drop-down (15pts), and finally the sticky checkboxes (15pts).

For the function generating the drop-down: this means passing in an extra argument, indicating what option should be pre-selected (with, perhaps false or "" indicating no-option pre-selected). Recall that you can use “optional arguments” to make your code backwards compatible: function dropdown( $groupName, $entries, $title=false, $preSelected=false ). Now, the user can pass in a string (or, false) as the last argument, or they can just omit it entirely, and it's as if they'd passed in false, indicating no item is specifically pre-selected. That means that your old test cases (which omitted that argument) should still receive the exact same result as before, and nothing needs to change. Of course, you'll add an extra test-case or two which does pass in a string, to (a) figure out what your code needs to generate, and (b) that when finished your code runs as expected.

Similarly, the previous function checkboxes will want to take in an (optional) array-of-items to pre-check. I suggest that this array happen to be the same sort of contents that the form-handler receives in $_POST, to make it easy for the form-handler to call your new, improved checkboxes function.


Q: How on earth can we check that the sticky-form is correctly showing errors is including the sticky values, since our form's javascript doesn't let us submit when there are validation-errors?

A1: Remember those form-handle-demo pages we made? That's how you test the results of submitting a form w/o needing to type in the form-info, bypassing the form-page altogether!

A2: For temporary-testing, you could also change your form's onsubmit javascript from return validateAll(); to return validateAll() || true; — that way it will submit even if the validation fails.

Q: I'm getting a totally blank page. How do I track down the error?

A: If you're getting a 500 error -- a totally blank page -- that's probably php not even starting to run, perhaps due to a missing semicolon or something. Our solution is the same as it's been all semester: run locally (not via web), to see such error messages. In particular, php tq-edit-demo1.php will cause my form-handler to run, and therefore can track down such errors.

On the other hand, if php tq-edit-demo1.php runs successfully, you'll just be treated to a screen full of raw html. At that point, you can view the demo.php file via the web, or still bypass any web-issues by saving that output to a file and then open-file from inside the browser. You check by eye, that the output really includes the expected-sticky-values etc..

homelectsexamshws
D2Lbreeze (snow day)


©2015, Ian Barland, Radford University
Last modified 2015.Apr.13 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.