INTN 2201: Lab Assignment 6:
Advanced PHP Scripting

Due Date and Marking

Lab 6 is due by March 13th 2010, by midnight. This means that you must have sent an email with your link by that time (see "Handing In" section below). Be sure to include the course code, and the lab number in the subject line of the message (i.e. "INTN2201 Lab #6"). You will receive an email back within a day or two, giving you your mark out of twn, and the reasons for any loss of marks.

General

This is a challenging assignment but contains some important concepts that will be used in subsequent assignments and tests. You are recommended not to put this assignment off until the last minute.

You are to create a lab6.php, that is going to have an HTML form that refers the page back to itself and utilizes some PHP provided functions to handle data validation.

All this will be to the end of creating a dynamic temperature conversion table, based on users input.

A self-referring form with data validation has been provided for you (and was discussed in class), the content of the file can be found in lab6_lecture.txt. Take the contents of this file and place it in a new text file with a *.php extension, and you can see how it works.

To perform the data validation you will want to use some of the PHP provided functions: is_numeric() to determine if a number was entered, isset() to determine if the form data exists on the $_POST[ ] array, and trim() to remove any white space the user might have entered.

Additionally students should check out the $_SERVER[ ] array in the manual, looking specifically at the $_SERVER['REQUEST_URI'] or $_SERVER['PHP_SELF'] as a way of submitting a form to itself, and $_SERVER['REQUEST_METHOD'] to determine whether the page loads in "GET" mode (when the page first loads vs. "POST" which means the form has been submitted for processing.

Specific Requirements

  • You are to create a lab6.php, that is satisfies the requirements below.
  • The file you are to create for this assignment should include your header.php (which will automatically incorporate your intn2201.css stylesheet) and footer.php. This will assure the new file conforms to your existing page layout. Be sure to include a header <h1> element and a paragraph describing what the page does/instructions for the data to be entered. NOTE: Your page must still validate to the XHTML transitional standard.
  • Similar to previous assignments, include PHP comments with your name and course code in the PHP file created for this assignment. Additionally, add HTML comments to all your pages (this should occur if you implement your header.php file correctly).
  • The lab6.php is a PHP page that:
    • contains a self-referencing/self-submitting form(to achieve this the action attribute on the page's form should have <?php echo $_SERVER['REQUEST_URI']; ?> or <?php echo $_SERVER['PHP_SELF']; ?>)
    • the form should be submitted in POST mode
    • this page should, the first time the pages loads in the default GET mode, create empty string variables named $start, $stop, $incr, $error and $table.
    • has three (3) named text input boxes, one for a starting temperature, one for an ending temperature and one for the increment the user wants to increase the temperature by each.
    • when submitted in POST mode, should store the three (3) inputted values from the $_POST[ ] array in variables named $start, $stop, $incr
    • performs a check that the data submitted is valid. Valid data means:
      • that the user entered numbers in each field
      • that the start temperature is less than the end temperature
      • that the temperature increment is a positive (non-zero) number
      If any of these conditions are not met, an appropriate message should be placed in the $error variable and no calculation should be done or a table created, but the error message should be displayed. If any invalid data is entered, it should be incorporated as part of the error, but the variable subsequently should be emptied out.
    • If there are no errors, then the page should create an $table variable that contains a table of temperature conversion, that uses the entered numbers and a loop.
    • To see how the page should work check out the example provided.
    • NOTE: the form on the page should be "sticky", which means if vaild data was placed in the form, it will still be in the form when the page reloads. This can be achieved by echoing the variables from the $_POST[ ] array into the value attribute of the appropriate input box.

Handing In

Publish your pages on the opentech server and submit the URL of your index page to YOUR lab instructor. The preferred method/location for the various instructor is:

Instructor Method
Stephen Franks Place URL in the appropriate lab drop box on WebCT
John Mather Mail your URL to john.mather@durhamcollege.ca. BE SURE TO INCLUDE THE COURSE CODE AND LAB NUMBER IN THE SUBJECT LINE.
Darren Puffer Mail your URL to darren.puffer@durhamcollege.ca. BE SURE TO INCLUDE THE COURSE CODE AND LAB NUMBER IN THE SUBJECT LINE.

Don't mail your files themselves or save them into WebCT; they are useless away from the server.

To publish your pages, upload them to the server in the directory /var/www/users/intn2201/userid (this is the only folder that will work because that's what the Apache Web server software is configured to look in for your files).
Keep your files on-line until you are sure they have been marked!
Directory and file names on the server are case-sensitive, so be sure to put everything in lowercase letters. The default page name is index.html. Don't use spaces, apostrophes, uppercase letters or quotation marks in your file name (keep it simple, using letters and digits, otherwise people won't find your pages).

Linking file names to URLs

Let's say your login ID is speedy, then your file name on the server is:
 /var/www/user/intn2201/speedy/index.html
The corresponding URL is:
 http://opentech.durhamcollege.ca/~intn2201/speedy/
Don't forget the ~ (tilde) symbol. It means "speedy's home directory".

For the rest of the files in your site, you need to give the name in the URL. The file named:
 /var/www/users/intn2201/speedy/page2.html
has the corresponding URL is:
 http://opentech.durhamcollege.ca/~intn2201/speedy/page2.html


Valid XHTML 1.0 Transitional

Valid CSS!