<?php
include('includes/header.php');
// code
error_reporting(E_ALL); // set error reporting to all
echo('<h1>Isaac\'s Area of a Rectangle Form</h1>');
// Note the variables being passed via the POST ternary operators.
$step = isset($_POST['step']) ? $_POST['step'] : 0;
$width = isset($_POST['width']) ? $_POST['width'] : '';
$length = isset($_POST['length']) ? $_POST['length'] : '';
// filter all input taken from the Browser
$step = htmlentities($step);
$width = htmlentities($width);
$length = htmlentities($length);
if ($step == 0) // first time into this form
{
?>
<form action="area-of-rectangle.php" method="POST">
<label for="name">Length</label>
<input type="text" size="36" id="name" name="length" value="">
<br><br> Width
<input type="text" size="36" id="name" name="width" value="">
<br><br>
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Submit">
</form>
<?php
} else // else show what the form gathered
{
echo('<p>The following is what the form gathered</p>');
echo('<p>The area of your rectangle is</p>');
echo('<pre>');
print_r($_POST); // note this dumps the entire contents of the $_POST array
echo('</pre>');
$area = $width * $length;
echo("<h3> Area = $area</h3>");
// provide a form to try again
?>
<form action="area-of-rectangle.php" method="POST">
<input type="hidden" name="step" value="0">
<input type="submit" name="submit" value="Try Again">
</form>
<?php
}
include('includes/footer.php');
?>