    <?php
error_reporting(E_ALL);


      if ($_POST['submit'] == 'Register' ){
          
          foreach ($_POST as $key=>$value){
              if (is_array($_POST[$key])){
                    $content .= '<strong>'.ucfirst($key).'</strong>: ';
                     foreach ($_POST[$key] as $val){
                         $content .= $val.' ,  ';    
                      }
               $content .= '<br>';    

               }
              else 
                 {   
                 if ($key == 'submit') continue;//this is to ignore the button!
                   
                $content .= '<strong>'.ucfirst($key).'</strong>: '.trim($value).'<br>';  
              }
          }  
         echo $content;  
         $bool = mail('ksecor@sdccd.edu','New Registrant',$content,"Content-type: text/html");
         if ($bool) echo 'You have been registered!';
          
          
        //this is how to deal with checkboxes!!!!!
        //  var_dump($_POST['hobbies']);
        //  if (isset($_POST['hobbies'])) echo $_POST['hobbies'].'<br>';
        //  if (isset($_POST['comments'])) echo $_POST['comments'].'<br>';
      }

    ?>
    <form action ="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
    Name: <input type="text" name = "fullname" required value="<?php echo $_POST['fullname'];?> "><br>
    Gender:<br> 
    Male: <input type="radio" name="gender" value="Male" required 
         <?php
             if ($_POST['gender'] == 'Male') echo ' checked ';  ?>>
        
     Female <input type="radio" name="gender" value="Female" 
         <?php
             if ($_POST['gender'] == 'Female') echo ' checked ';            
         ?>/><br> 
    Year in School <select name ="year" required>
    <option value ="">Choose Below</option>    
    <option value ="Freshman"   
    <?php if  ($_POST['year'] == 'Freshman') 
    echo ' selected '; ?>
            >Freshman</option>
    <option value ="Sophomore"  <?php if  ($_POST['year'] == 'Sophomore') 
    echo ' selected '; ?>>Sophomore</option>
    <option value ="Junior"  <?php if  ($_POST['year'] == 'Junior') 
    echo ' selected '; ?>>Junior</option>
    <option value ="Senior"  <?php if  ($_POST['year'] == 'Senior') 
    echo ' selected '; ?>>Senior</option>
    </select><br>
        Courses you have taken:
        <input type="checkbox" name='php' value='php'  <?php if ($_POST['php'] == 'php') echo ' checked ';?>>PHP<br>  
        <input type="checkbox" name='html' value='html'  <?php if ($_POST['html'] == 'html') echo ' checked ';?>>html<br>  
        <input type="checkbox" name='javascript' value='javascript'  <?php if ($_POST['javascript'] == 'javascript') echo ' checked ';?>>JavaScript<br>  
        Hobbies:
        <input type="checkbox" name='hobbies[]' value='tennis' <?php
          if (in_array('tennis',$_POST['hobbies'])) echo ' checked ';
               
               ?>>Tennis<br>  
        <input type="checkbox" name='hobbies[]' value='baseball'                <?php      if (in_array('baseball',$_POST['hobbies'])) echo ' checked ';
 ?>
>Baseball<br>  
        <input type="checkbox" name='hobbies[]' value='Hockey'  
               <?php
               if (in_array('Hockey',$_POST['hobbies'])) echo ' checked ';
               ?>
>Hockey<br>  

        
     Comments:
    <textarea name="comments" required><?php echo $_POST['comments'];?></textarea><br>
    <input type="submit" name ="submit" value="Register">

    </form>