<?php
  if (isset($_GET['source'])) {
        highlight_file($_SERVER['SCRIPT_FILENAME']);
        exit;
  }
?>
<html>
<head>
<title>PHP and Web Forms</title>
    
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="theme-color" content="#B5C7DD" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="../css/reset.css">
        <link rel="stylesheet" href="../css/mandy.css">
        <link rel="stylesheet" href="../css/form.css">

<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
</head>
<body>
    
<h2 class="pad-top">    
    
<?php   # need this to be able to view source in the below anchor tag
  $urlPath=dirname($_SERVER['SCRIPT_URL']).'/'; 
  $labsPath=$urlPath.'labs/'; 
?>     

    <a href="../index.php">CS 130A</a> → Lab 5
<a href="<?=$urlPath?>edit.php?source" target="labs">Source code</a>

</h2>   

<h4>Car Payments Formula</h4>
    
<?php      
//  works identically and commented so in the payments.php file
$loan = $_POST['loan'];
$months = $_POST['months'];
$rate = $_POST['rate'];

       
       $payment = $_POST['payment'];
?>
 <form action="payments.php" method=post name="calculate" id="calculate"> 

<div class="pad-top">  

<label for="loan">Loan Amount: $</label>    
<input type="number" step="0.01" name="loan" id="loan" value="<?=$loan?>" required /> 
 
</div>   

<label for="months">Number of Months:</label>    
<input type="number" name="months" id="months" value="<?=$months?>" class="space" required /> months
 
 <br />      

<label for="rate">Yearly Rate:</label>
<input type="number" step="0.01" name="rate" id="rate" value="<?=$rate?>" class="space" required  />   %      
     
  
<div class="pad-top">
<label for="Payment:">Payment: $</label>
<input type="text" name="payment" id="payment" value="<?=$payment?>" class="space" readonly />  per month       
</div>    
     
<!--     Reset button here doesn't actually reset but brings you back to the original index page with the form-->
<div class="pad-top">     
<input type="submit" formaction="index.php" value="Reset" class="button">    
    
<!--     submit sends you to payments.php-->
<input type="submit" name="submit" value="Submit" class="space button">
</div>     
      
</form>
 
<pre>

<?php   
  
    
?>     

</pre>    
    <p class="hide">
    this is a blank paragraph to do nothing but take up space and ensure the formatting works
    </p>
    <div class="stretch"></div>
</body>
</html>