<?php
error_reporting(E_ALL);
//var_dump($_SERVER['HTTP_REFERER']);
//var_dump($_SERVER);
//echo basename($_SERVER['HTTP_REFERER']); will equal form.php
//echo basename($_SERVER['PHP_SELF']); will equal form.php
//echo $_SERVER['HTTP_REFERER'];
//var_dump($_SERVER);
if ($_SERVER['HTTP_HOST'] == 'mm214.com' && $_SERVER['PHP_SELF'] == '/form1.php' && $_POST['submit'] == 'Register'){
	//this is one way!!!!
/*
echo $_POST['fullname'].'<br>';
echo $_POST['email'].'<br>';
echo $_POST['tel'].'<br>';
echo $_POST['year'].'<br>';
foreach($_POST['subject'] as $sub){
	echo $sub.', ';
}
echo '<br>';
echo $_POST['time'].'<br>';
echo $_POST['comments'];
*/
//This is a super awesome way! Dynamic!

foreach ($_POST as $key=>$value){
   if ($key == 'submit') continue;
   if (is_array($value)){
   		$content .=  '<strong>'.ucfirst($key).'</strong>  : ';
   	   foreach ($value as $indval){
   	   	$content .= $indval.', '; 
   	   }
   	   $content = substr($content,0,strlen($content)-2).'<br>';
   		//need to loop around that bad boy!
   }
   else {
         $content .= '<strong>'.ucfirst($key).'</strong> : '.$value.'<br>';
   }
   
}

   echo $content;
  mail('kdsecor@gmail.com','Contact Info',$content,"Content-type: text/html");

	//output
	//mail
//var_dump($_POST);



}
//explain $GLOBALS
?>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<label for = "fullname">Full Name:</label><input type="text" name="fullname" id="fullname"><br>
<label for = "email">Email:</label><input type="email" name="email" id="email" placeholder="Email Address Here"><br>

<label for = "tel">Telephone:</label><input type="tel" name="tel" id="tel" placeholder=""><br>
Year in School: <label for = "freshman">Freshman</label><input type="radio" name="year" value="freshman"> <label for = "sophomore">Sophomore</label><input type="radio" name="year" value="sophomore"><label for = "junior">Junior</label><input type="radio" name="year" value="junior"><label for = "senior">Senior</label><input type="radio" name="year" value="senior"><br>
Favorite Subjects:
<label for = "math">Math</label><input type="checkbox" name="subject[]" id="math" value="math">
<label for = "english">English</label><input type="checkbox" name="subject[]" id="english" value="english">

<label for = "history">History</label><input type="checkbox" name="subject[]" id="history" value="history">

<label for = "computer">Computer Science</label><input type="checkbox" name="subject[]" id="computer" value="computer"><br>
When is your preferred time to take classes?<br>
<select name ="time">
<option value="">Choose Below</option>
<option value="morning">Morning</option>
<option value="afternoon">Afternoon</option>
<option value="evening">Evening</option>
</select><br>
Comments:<br>
<textarea name="comments"></textarea><br>
<input type="submit" name="submit" value="Register">
</form>





</form> 