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

homelectsexamshws
D2Lbreeze (snow day)

hw03
php producing html

Due: 2013.Feb.14 (Thu) 23:59, on D2L dropbox hw03 (and, online).
(Will be accepted through Feb.17 (Sun.) 23:59, but hw04 will be out concurrently.)

For this homework, you will submit four files (utils.php, utils-test.php, wow-constants.php, and skill-form.php) on D2L. In addition, I will visit the URL https://php.radford.edu/~yourUserName/itec325/hw03/skill-form.php to grade your work. If that URL is not accessible, you will get a 0 for that portion of the grading! (Be sure to get the name exactly right: a itec325 folder containing a hw03 folder.) Also, note that good test cases comprise nearly half of the points-possible, for problems that have you write a function.

  1. (10pts) Write a function which takes in an array of strings, and returns a single, long string: a comma-separated list of all the individual strings, with “and” before the last element (if more than one)1. The resulting string should be suitable for splicing into the middle of a paragraph of prose, and should be proper, grammatical English. (This function has nothing to do with html.) Include at least three test cases, each testing a different situation.
  2. (20pts) Write a function which takes in an array of strings (checkbox-descriptions) (and, a group-name), and returns a string that happens to be valid html for a series of checkboxes. The string should include newlines, and (if you want) each line might start with (say) 6 spaces, to serve as indentation.

    For example, calling checkboxes( 'family', array('Brother', 'Sister', 'Pet') ) would return html which renders as something like:




    Include at least two test cases; you'll probably want to write a sample series of checkboxes by hand, to serve as your expected-output. Use label tags to group each checkbox with its adjacent text.

  3. (10pts) Include a function named (something like) arrayToHTML_table, which takes in an array and returns a string: the HTML markup for a two-column table, with the array-indices in the first column and the array-values in the second.

    For example, arrayToHTML_table( array( "en" => "Hi", "de" => "'Tag", "fr" => "'Allo" ) ) should return HTML which renders as something like:

    enHi
    de'Tag
    fr'Allo

    Include at least two test cases. (What if one of the strings contains, say, an ampersand character?) I suggest first writing the raw html for the table, and then cutting/pasting that html in as the expected-result; this will help you decide what whitespace etc. you want your function to produce.

    Hint: I found my solution to actually be simpler by making a second helper function, twoStrsToHTML_tr, that only had two worry about creating a single row. Having test cases for the helper also let me have fewer/simpler tests for the main function.

  4. (10pts) Write a function navlinksUL: It takes an array of strings, and returns a string that is HTML for an un-ordered list of links to anchors within the same document.

    For example, given an array with "commaList-prob", "checkbox-prob" and "due-date", it would return HTML that would render as:

    (Of course, this function is only helpful on a web page with elements whose ids match the strings in the array. Try clicking on those items, and feel free to view-source, to understand what it's doing.)

  5. (10pts)

    Finally, create a web-page skill-form.php which makes use of all four of the above functions, and renders something like: sample goal page.

    Note that this page is not actually a submittable form; it will just contain some checkboxes and an entry field; the submit button does nothing. (We'll get to that soon!)

    You should also have one short, extra file wow-constants.php, which simply initializes two variables: one array with the 4 types of characters, and one array with the 6 character attributes (with their abbreviations as keys). (We'll add more to this file in future homeworks.)

    Your skill-form.php will require_once your files with the utilities and constant-definitions.


Other requirements

These apply to all homeworks for this class:

1I personally recommend using the Oxford comma, but will leave it to your preference.      

2the function to show-source a file is one of the few exceptions      

homelectsexamshws
D2Lbreeze (snow day)


©2012, Ian Barland, Radford University
Last modified 2013.Feb.14 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme