<?php
    /*-----
        function: request_color
        purpose: expects nothing, returns nothing,
            but has the side-effects of trying to
            read the desired quest from the requesting
            form, and saves that quest for later use
            while also using it in a customized
            response and color-form
    -----*/
    
    function request_color()
    {
        // if get here -- better be a quest in $_POST!

        // (trim removes leading and trailing blanks
        //     from a string... 8-) )

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

        // if get here -- I think I can proceed

        $user_quest = strip_tags($_POST['quest']);
        $_SESSION['quest'] = $user_quest;

        $user_name = strip_tags($_SESSION['name']);

        ?>

        <h2> 
            AHA, <?= $user_name ?>, 
            your quest: <?= $user_quest ?> is NOBLE 
            indeed! BUT - what is your FAVORITE COLOR?
        </h2>

        <form method="post"
              action="<?= htmlentities($_SERVER['PHP_SELF'],
                                       ENT_QUOTES) ?>">
            <input type="text" name="color" 
                   required="required" />
            <input type="submit" value="submit color" />
        </form>
        <?php
    }
?>