<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<!--
    our first PHP postback!

    by: Sharon Tuttle
    last modified: 2024-03-19

    you can run this using the URL:
    https://nrs-projects.humboldt.edu/~st10/s24cs328/328lect09-2/php-form-handling.php

    strict-validated as follows:
    *   to validate its form:
        *   open this PHP in a browser to display the form

        *   in the browser, view source and copy that resulting
            source

        *   in nrs-projects, open nano/vi/emacs and paste in that
            source into a file php-form-handling-1.xhtml

        *   put the URL for php-form-handling-1.xhtml into
            https://validator.w3.org/nu/ or https://html5.validator.nu/

    *   to validate its form response:
        *   enter input into the form in a browser to generate a result

        *   in the browser, view source and copy that resulting
            source

        *   in nrs-projects, open nano/vi/emacs and paste in that
            source into a file php-form-handling-2.xhtml

        *   put the URL for php-form-handling-2.xhtml into       
            https://validator.w3.org/nu/ or https://html5.validator.nu/
-->

<head>
    <title> php-form-handling.php </title>
    <meta charset="utf-8" />

    <link href="https://nrs-projects.humboldt.edu/~st10/styles/normalize.css"
          type="text/css" rel="stylesheet" />

</head>

<body>
    <h1> Our FIRST form handled by PHP </h1>

    <?php

    // if this page has just been requested, produce a form 

    if ($_SERVER["REQUEST_METHOD"] == "GET")
    {
    ?>
        <form method="post"
              action="<?= htmlentities($_SERVER["PHP_SELF"], ENT_QUOTES) ?>">
            <label for="username"> Enter your name: </label>
            <input type="text" name="username" id="username" /> <br />

            <label for="bday_month"> Enter your birthday month: </label>
            <input type="text" name="bday_month" id="bday_month" /> <br />

            <input type="submit" />
        </form>
    <?php
    }

    // otherwise, this better be a submitted form -- handle
    //     what the user submitted

    else
    {
        ?>
        <p> Welcome, <?= htmlspecialchars($_POST["username"]) ?>! </p>
        <p> You will get a special discount in
            <?= strip_tags($_POST["bday_month"]) ?>. </p>
        <?php
    } 
    ?>

    <footer>
    <hr />
    <p>
        Validate by pasting .xhtml copy's URL into<br />
        <a href="https://validator.w3.org/nu">
            https://validator.w3.org/nu
        </a>
        or  
        <a href="https://html5.validator.nu/">
            https://html5.validator.nu/
        </a>
    </p>
    </footer>
</body>
</html>