<?php
    /* stub version to start */

    /*=====
    function request_color()
    {
        ?>
        <p> called function request_color </p>
        <p> <a href="<?= htmlentities($_SERVER["PHP_SELF"],
                                       ENT_QUOTES) ?>">
            Continue </a> </p>
        <?php
    }
    =====*/

    /* end of stub version */
?>

<?php
    /*=====
        function: request_color
        purpose: expects no parameters, and tries to read
            the user's quest from the requesting
            form, and (safely) use that PLUS $_SESSION["name"]
            to make a personalized, quest-including
            request for a favorite color

            *   ALSO saves that quest in $_SESSION for
                future-application use

        requires: build_mini_form.php

        by: Sharon Tuttle
        last modified: 2025-04-23
    =====*/

    function request_color()
    {
        // make sure a quest was submitted

        if ( (! array_key_exists("quest", $_POST) )
             or (trim($_POST["quest"]) == "") )
        {
            complain_and_exit("quest");
        }

        // if I get here, there WAS a quest entered;
        //    sanitize it and save it for later-state use

        $user_quest = trim(htmlspecialchars($_POST["quest"]));

        $_SESSION["quest"] = $user_quest;

        // get desired info from previous state(s)

        $user_name = trim(htmlspecialchars(strip_tags($_SESSION["name"])));

        // craft personalized response for a color including noting
        //    their quest
        ?>
        <h2> AHA, <?= $user_name ?>, <br />
             your quest: <?= $user_quest ?> <br />
             is NOBLE indeed! </h2>
        <h2> BUT - WHAT is your FAVORITE COLOR? </h2>

        <?php
        build_mini_form("color", "Submit it");
    }

?>