Document

Steph's $_POST form









<?php
//Gather the $_POST variables.
// Turnary - If first name is set then use it otherwise get it else use 0.
$isFirstTime = isset($_POST['isFirstTime']) ? $_POST['isFirstTime'] : 0;
$firstName   = isset($_POST['firstName'])   ? $_POST['firstName']   : '';
$lastName    = isset($_POST['lastName'])    ? $_POST['lastName']    : '';
$email       = isset($_POST['email'])       ? $_POST['email']       : '';
$phone       = isset($_POST['phone'])       ? $_POST['phone']       : '';

//Filter input taken from the browser/sanitizes input
$isFirstTime = htmlentities($isFirstTime);
$firstName   = htmlentities($firstName);
$lastName    = htmlentities($lastName);
$email       = htmlspecialchars($email);
$phone       = htmlentities($phone);

error_reporting(E_ALL);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>POST</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 $_POST 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="postForm.php" method="POST" 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($_POST); ?></pre>

        <!-- Reset form button/Try again -->
        <form action="postForm.php" method="POST">
            <input type="hidden" name="isFirstTime" value="0">
            <input type="submit" name="submit" value="Try Again">
        </form>
    <?php endif; ?>
    <?php
    
// This will display the source code of the file
    
show_source(__FILE__);
    
?>
</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');
?>

</body>
</html>