<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Unit 10, Hands-On Exercise 2</title>

<?php

// Display a red asterisk

function redstar( )
{
?>
<span style="font-size:14pt;color:red;font-weight:bold">*</span>&nbsp;
<?php
}
?>

</head>

<body>
<?php

if ( $_POST )    // POST request
{
    printf( "<h1>Processing the Form</h1>" ) ;
?>

<?php /* ?>
<pre>
<?php */ ?>

<?php 

//print_r( $_POST ) ;    // dump entire $_POST array

$username = $_POST[ 'username' ] ;

$address1 = $_POST[ 'address1' ] ;

$address2 = $_POST[ 'address2' ] ;

$city = $_POST[ 'city' ] ;

$prov = $_POST[ 'prov' ] ;

$code = $_POST[ 'code' ] ;

?>
<table border="1">
<tr><th>Name</th><td><?php echo( $username ) ; ?></td></tr>
<tr><th>Address</th><td><?php printf( "%s<br>%s", $address1, $address2 ); ?></td></tr>
<tr><th>City</th><td><?php echo( $city ) ; ?></td></tr>
<tr><th>Province/Territory</th><td><?php echo( $prov ) ; ?></td></tr>
<tr><th>Postal Code</th><td><?php echo( $code ) ; ?></td></tr>
</table>

<?php /* ?>
</pre>
<?php */ ?>

<?php

}
else    // GET request
{

?>
 <h1>Request a Brochure</h1>

 <form method="post" id="brochureform" 
  action="<?php echo( $_SERVER[ 'SCRIPT_NAME' ] ); /* URL of this script */ ?>">

   <p>Enter the following information.  Fields marked with a 
   <?php redstar(); ?> are required.</p>
 
  <div>
   <label for="username">Your Name:</label>
   <?php redstar(); ?><input type="text" id="username" name=
    "username" maxlength="30" required="required">
  </div>

  <div>
    <fieldset>
    
      <legend>Mailing Address</legend>

      <label>Address 1: <?php redstar(); ?><input type="text" id=
       "address1" name="address1" required="required"></label><br />
       
      <label>Address 2: <input type="text" id="address2" name=
       "address2"></label><br />
       
      <label for="city">City/Town:</label> <?php redstar() ;?><input type=
       "text" id= "city" name="city" list="cities" required="required"><br />
       
        <datalist id="cities">
          <option label="Abbotsford, BC">Abbotsford</option>
          <option label="Barrie, ON">Barrie</option>
          <option label="Brampton, ON">Brampton</option>
          <option label="Burlington, ON">Burlington</option>
          <option label="Burnaby, BC">Burnaby</option>
          <option label="Calgary, AB">Calgary</option>
          <option label="Cambridge, ON">Cambridge</option>
          <option label="Cape Breton, NS">Cape Breton</option>
          <option label="Coquitlam, BC">Coquitlam</option>
          <option label="Delta, BC">Delta</option>
          <option label="East York, ON">East York</option>
          <option label="Edmonton, AB">Edmonton</option>
          <option label="Etobicoke, ON">Etobicoke</option>
          <option label="Gatineau, QC">Gatineau</option>
          <option label="Gloucester, ON">Gloucester</option>
          <option label="Guelph, ON">Guelph</option>
          <option label="Halifax, NS">Halifax</option>
          <option label="Hamilton, ON">Hamilton</option>
          <option label="Kelowna, BC">Kelowna</option>
          <option label="Kitchener, ON">Kitchener</option>
          <option label="Laval, QC">Laval</option>
          <option label="London, ON">London</option>
          <option label="Longueuil, QC">Longueuil</option>
          <option label="Markham, ON">Markham</option>
          <option label="Mississauga, ON">Mississauga</option>
          <option label="Montr&eacute;al, QC">Montr&eacute;al</option>
          <option label="Nepean, ON">Nepean</option>
          <option label="North York, ON">North York</option>
          <option label="Oakville, ON">Oakville</option>
          <option label="Oshawa, ON">Oshawa</option>
          <option label="Ottawa, ON">Ottawa</option>
          <option label="Qu&eacute;bec, QC">Qu&eacute;bec</option>
          <option label="Regina, SK">Regina</option>
          <option label="Richmond, BC">Richmond</option>
          <option label="Richmond Hill, ON">Richmond Hill</option>
          <option label="Saanich, BC">Saanich</option>
          <option label="Saint Catharines, ON">Saint Catharines</option>
          <option label="Saint John's, NF">Saint John's</option>
          <option label="Saskatoon, SK">Saskatoon</option>
          <option label="Scarborough, ON">Scarborough</option>
          <option label="Sudbury, ON">Sudbury</option>
          <option label="Surrey, BC">Surrey</option>
          <option label="Thunder Bay, ON">Thunder Bay</option>
          <option label="Toronto, ON">Toronto</option>
          <option label="Vancouver, BC">Vancouver</option>
          <option label="Vaughan, ON">Vaughan</option>
          <option label="Windsor, ON">Windsor</option>
          <option label="Winnipeg, MB">Winnipeg</option>
          <option label="York, ON">York</option>
        </datalist>

       
      <label for="prov">Province:</label> 
      
       <?php redstar(); ?><select id="prov" name="prov" required="required">
       
        <option value="">--Please select a Province or Territory--</option>
        <option value="YT">Yukon Territory</option>
        <option value="BC">British Columbia</option>
        <option value="NT">Northwest Territories</option>
        <option value="AB">Alberta</option>
        <option value="SK">Saskatchewan</option>
        <option value="NV">Nunavut</option>
        <option value="MB">Manitoba</option>
        <option value="ON">Ontario</option>
        <option value="QC">Qu&eacute;bec</option>
        <option value="NB">New Brunswick</option>
        <option value="NS">Nova Scotia</option>
        <option value="PE">Prince Edward Island</option>
        <option value="NL">Newfoundland and Labrador</option>
        
       </select><br />
       
      <label>Postal Code: <?php redstar(); ?><input type=
        "text" size="7" maxlength="7" id="code" name=
        "code" required="required"></label>
        
    </fieldset>
  </div>
 
  <div>
    <input type="reset" value="Clear Form">
    <input type="submit" value="Submit Form">
  </div>
  
 </form>
 
<?php

}    // end else 

?>
 
</body>
</html>