<?php
    /* stub version to start */
    /*=====
    function request_quest()
    {
        ?>
        <p> called function request_quest </p>
        <p> <a href="<?= htmlentities($_SERVER["PHP_SELF"],
                                       ENT_QUOTES) ?>">
            Continue </a> </p>
        <?php
    }
    =====*/
    /* end of stub version */
?>

<?php
    /*====
        function: request_quest
        purpose: expects no parameters, and tries to read
            the user's name from the submitted form
            and (safely) use that name in a new 
            response-including-form requesting the user's 
            quest;

            *   ALSO saves that user's name in $_SESSION for
                future-application use

        requires: build_mini_form.php

        by: Sharon Tuttle
        last modified: 2026-04-22
    ====*/
    
    function request_quest()
    {
        // IF I get here -- there BETTER be a name in the $_POST array!
        //     here, am choosing to complain and exit if this is
	//     not the case

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

        // if reach here, SHOULD be some kind of name entered;
        //    grab it, sanitize it, keep it for later

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

        $_SESSION["name"] = $user_name;

        // craft a personalized response including a quest-request

        ?>
	<h2> Well, <?= $user_name ?>, WHAT is your QUEST? </h2>
        <?php
	
	build_mini_form("quest", "Submit it");
    }
?>