<?php
//Gather the $_GET variables.
// Turnary - If first name is set then use it otherwise get it else use 0.
$isFirstTime = isset($_GET['isFirstTime']) ? $_GET['isFirstTime'] : 0;
$firstName = isset($_GET['firstName']) ? $_GET['firstName'] : '';
$lastName = isset($_GET['lastName']) ? $_GET['lastName'] : '';
$email = isset($_GET['email']) ? $_GET['email'] : '';
$phone = isset($_GET['phone']) ? $_GET['phone'] : '';
//Filter input taken from the browser/sanitizes input
$isFirstTime = htmlentities($isFirstTime);
$firstName = htmlentities($firstName);
$lastName = htmlentities($lastName);
$email = htmlspecialchars($email);
$phone = htmlentities($phone);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Get</title>
<!-- Header, footer, and primary layout styles also used in other files -->
<link rel="stylesheet" href="../css/assignmentHeaderStyles.css" />
<!-- Specific form styling -->
<link rel="stylesheet" href="../css/week3Assignment.css" />
</head>
<body>
<?php
// Include header inside the <body> so Flexbox tracks it correctly and its not all weird.
include ('../header/assignmentHeader.php');
?>
<!-- Main wrapper fills the screen space and pushes footer down -->
<main class="site-main container">
<h1>Steph's $_GET form</h1>
<?php if ($isFirstTime == 0): ?>
<!-- 0 means it is the first time this user has been here and 1
means it is not there first time. Setting it as 0 means the sit will prompt anything that is a first time visit -->
<form action="getForm.php" method="GET" class="colectingPersonalInformation">
<label for="FirstName">First Name</label>
<input type="text" size="36" id="FirstName" name="firstName" value="<?php echo $firstName; ?>">
<br><br>
<label for="lastName">Last Name</label>
<input type="text" size="36" id="lastName" name="lastName" value="<?php echo $lastName; ?>">
<br><br>
<label for="email">Email</label>
<input type="email" size="36" id="email" name="email" value="<?php echo $email; ?>">
<br><br>
<label for="phone">Phone</label>
<input type="text" size="36" id="phone" name="phone" value="<?php echo $phone; ?>">
<br><br>
<input type="hidden" name="isFirstTime" value="1">
<input type="submit" name="submit" value="Submit">
</form>
<?php else: ?>
<!-- Submitted = Show the human readable data by using print_r -->
<p>The following is what the form gathered</p>
<pre><?php print_r($_GET); ?></pre>
<!-- Reset form button -->
<form action="getForm.php" method="GET">
<input type="hidden" name="isFirstTime" value="0">
<input type="submit" name="submit" value="Try Again">
</form>
<?php endif; ?>
<br><hr><br>
<h2>Source Code</h2>
<?php show_source(__FILE__); // output the syntax-highlighted source code of the currently executing file directly to the browser?>
</main>
<?php
// Putting the footer at the bottom of the body puts the footer at the bottom of the page as it should be.
include ('../footer/footer.php');
?>