CS1102 Lab 13

Does my BMI look big in this?

Inside your public_html/cs1102 folder, create a subdirectory called lab13 (all lowercase) to hold this week's work. Then create a file called bmi.php (based, of course, on template.php).

I advise you to tackle each of the following steps separately and test your script before moving on to the next step. (You won't heed my advice, of course. You're probably not even reading this parenthetical remark, are you? No, I thought not. f I wrte it az f it wer an sms, wud dat mAk U mo lIklE 2 rED it? No, I thought not.)

  1. First, write XHTML to display a form. The form should contain two labels, two text-fields and a submit button. The first text-field is for the user's weight in kg; the second text-field is for the user's height in metres. Make sure it displays correctly before moving on to step 2.
  2. Second, make this a self-processing page. Add PHP which will check whether we are showing this form to the user for the first time and, if we are not, will obtain the user's data, compute the user's Body Mass Index (BMI) and include this in the output.

    When measurements are in metric, then BMI = weight / (height * height).

    Test it before moving on to step 3.

  3. Third, make the form sticky.

    Test it before moving on to step 4.

  4. Fourth, include some validation of the user's input. Both the weight and height are mandatory, both must be positive numbers, weight will not exceed 600kg, and height will not exceed 3 metres. Output suitable error messages if any of these conditions is violated.

    Test it...Congratulations, you now have a working program.

  5. Fifth, we are now going to give our user a choice of metric or imperial weights and measures:
    1. add to your form a radio button labelled Metric and a radio button labelled Imperial
    2. the metric button will already be checked when the user first views the form
    3. if the user selects imperial (pounds and inches), then things are different:
      • the maximum weight is now 1325 pounds
      • the maximum height is now 120 inches
      • BMI = (weight * 703) / (height * height)
    Test it...
  6. Sixth, use the following table to advise the user of his/her status:
    BMI < 18.5Underweight
    18.5 ≤ BMI < 25Normal
    25 ≤ BMI < 30Overweight
    30 ≤ BMIObese
  7. Seventh, look at your script. Have you defined any functions to make your code more readable, maintainable, testable and re-usable? No? Then do so.

    Test it...

  8. Eighth. You already tested your script, yes? Look again. Is your radio button sticky? If so, well done. If no, sort it out!
  9. Ninth. How about a stylesheet to make it all look nice?
  10. Tenth. There is no tenth step.

Zip your lab13 folder and submit lab13.zip in the usual way, selecting LAB13 when asked.

Deadline: 1pm, Tuesday 12th February.