CSC220 Homework 3 Solutions 2010

From dftwiki3
Revision as of 08:10, 13 October 2010 by Thiebaut (talk | contribs) (Created page with '--~~~~ ---- == hw3form.htm == <code><pre> <!--Homework #3 Millicent Walsh csc220-ac hw3form.htm This is a form requesting information from students participating in an experime…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut 13:10, 13 October 2010 (UTC)


hw3form.htm

<!--Homework #3
Millicent Walsh
csc220-ac
hw3form.htm

This is a form requesting information from students participating
in an experiment for our class.

The data is processed by a php program called hw3process.php.

Different answers will be given to the user depending on how she
answers some of the questions, in particular whether she will use
her iPhone or not.

-->

<HTML> 
<HEAD> 
<TITLE>CSC220 Experiment</TITLE> 
<meta http-equiv="Pragma" content="no-cache"> 
</HEAD> 

<BODY> 
  <FORM ACTION="hw3process.php" METHOD="GET"> 
  <!--  <FORM ACTION="echoform.php" METHOD="GET">--> 

  <table border="1" bgcolor="#F2E4D5"> 
    <tr>
      <td colspan = "2" align = "center">
	<h2>Computer Science 220</h2>
	Please fill this personal information form out prior to starting experiment. <br>
	Remember all information will remain private.<br>  
	Thank you for participating!<br>
      </td>
    </tr>

    <!--Name-->
    <tr>
      <td>Your name:</td>
      <td><INPUT TYPE="text" NAME="name" SIZE="30"></td>
    </tr> 

    <!--Email-->
    <tr>
      <td>Your email address:</td>
      <td><INPUT TYPE="text" NAME="email" SIZE="30"></td>
    </tr>

    <!--Year-->
    <tr>
      <td>
	Indicate your current year at Smith. 
      </td> 
      <td>  
	<SELECT NAME="year" SIZE="1"> 
          <OPTION>First Year
          <OPTION>Sophomore
          <OPTION>Junior
          <OPTION>Senior
          <OPTION>Ada Comstock
          <OPTION>Faculty
	  <OPTION>Other
        </SELECT>
      </td>
    </tr>    
  
    <!--Major-->
    <tr>
      <td>Major:</td>
      <td><INPUT TYPE="text" NAME="major" SIZE="30"></td>
    </tr> 
    <!--iPhone--> 
    <tr>
      <td>Will you be using your own iPhone?</td>
      <td><INPUT TYPE="radio" NAME="phone" VALUE="y">Yes
	<INPUT TYPE="radio" NAME="phone" VALUE="n">No</td>
    </tr>
    
    <!--Days-->
    <tr>
      <td>
        Days available to participate?
      </td>
      <td>
	<INPUT TYPE="checkbox" NAME="day1" VALUE="Monday" >Monday
        <INPUT TYPE="checkbox" NAME="day2" VALUE="Tuesday">Tuesday
	<INPUT TYPE="checkbox" NAME="day3" VALUE="Wednesday">Wednesday
	<INPUT TYPE="checkbox" NAME="day4" VALUE="Thursday">Thursday
	<INPUT TYPE="checkbox" NAME="day5" VALUE="Friday">Friday
	<INPUT TYPE="checkbox" NAME="day6" VALUE="Saturday">Saturday
	<INPUT TYPE="checkbox" NAME="day7" VALUE="Sunday">Sunday
      </td>
    </tr>

    <!--How they heard about project-->
    <tr>
      <td>How did you hear about this experiment?</td>
      <td><TEXTAREA NAME="discovery" ROWS=6 COLS=40></TEXTAREA></td>  
    </tr>
    
    <!--information-->
    <tr>
      <td>
	Yes, I have read the information: 
      </td>
      <td>
	<INPUT TYPE="checkbox" NAME="box" VALUE="yes">
      </td>
    </tr> 

    <!--Submit and Reset buttons-->
    <tr>
      <td>
        Submit data <INPUT TYPE="SUBMIT" VALUE="Submit"> 
      </td>
      <td>
	Reset data fields: <INPUT TYPE="reset"> 
      </td>
    </tr> 
  </table> 
  </FORM> 
</BODY>
</HTML>


hw3process.php


<html>
<head>
<title>Php Process-Form -- CSC220</title>
</head>
<body>
<div>
<h2>Your Information</h2>

<?php
/*
Homework#3 
Millicent Walsh
csc220 
hw3process.php

Php program that process and displays information 
from the html form hw3form.htm.

Two different outputs are generated depending on whether the
user will use her iPhone or not, and whether she agrees to participate
or not.

*/

//Requesting all the information 
$name = $_GET["name"];
$year = $_GET["year"];
$major = $_GET["major"];
$email = $_GET["email"];
$read = $_GET["box"];
$reason = $_GET["discovery"];
$phone = $_GET["phone"];

//Store days in an array.
$day_arr = array( $_REQUEST["day1"],
		  $_REQUEST["day2"],
		  $_REQUEST["day3"],
		  $_REQUEST["day4"],
		  $_REQUEST["day5"],
		  $_REQUEST["day6"],
		  $_REQUEST["day7"]);


//Checks for required information: personal data phone and read documentation.
if($phone == "n"&& $read == NULL){
  print "We currently are not able to provide users with an iPhone.<br>";
  print "Thank you for your desire to participate, but a data phone is required<br>";
  print "<p>";
  print "Please return to form and read the given documentation.<br>";

}elseif($phone == "n"){
  print "We currently are not able to provide users with an iPhone.<br>";
  print "Thank you for your desire to participate, but a data phone is required<br>";
    
}elseif($read == NULL){
  print "Please return to form and read the given documentation.";

//Prints the users information for review.  
}else{  
  print "This student is<b> $name</b>.<br>";
  print "$name can be contacted by email at <b>$email</b>.<br>";
  
  if($major == !NULL){
    print "$name is  a <b>$major</b> major.<br>"; 
  }else{
    print "$name is a _______ major.<br>";
  }
  print "Personal iPhone: <b>Yes!</b><br>";
  
  //block displaying text about affiliation with Smith
  if($year == "Faculty"){    
    print "They are a <b>$year</b> member";
  }elseif($year == "Other"){
    print "For school affiliation you listed $year, please provide 
more detail in the given box.<br>";
  }else{
    print "$name is a <b>$year</b>.<br>";
  }  
  
  //print the days available
  print "<br>$name is available:<br>";
  foreach($day_arr as $key=>$value){
    if($value == !NULL){
      print "<b>$value</b><br>";
    }
  }

  //how they heard about the experiment
  print "<p>";
  print "How they heard about the experiment:<br>";
  print "<b>$reason</b>"; 

}
?>
</div>
</body>
</html>