<?php
    /*---
        function: make_three_value_response
        purpose: expects nothing, returns nothing,
            and responds to the form allowing the
	    user to enter three values

        by: Sharon Tuttle
        last modified: 2016-04-21
    ---*/

    function make_three_value_response()
    {
        ?>
        <h1> quick'n'sleazy response to three_value's form </h1>

        <?php
        // checking the passed values (because application
        //     tier MUST do this, no matter how much
        //     client-side checking is done -- anyone
        //     can try to LEAD to here...!)

        // trim will strip whitespace from the beginning and
        //     end of a string 

        $value1 = trim(htmlspecialchars($_GET['first']));
        $value2 = trim(htmlspecialchars($_GET['second']));
        $value3 = trim(htmlspecialchars($_GET['third']));

        if (($value1 == "") || ($value2 == "") || 
            ($value3 == ""))
        {
            ?>
            <p id="errors"> MUST fill in all textfields before
                submit! </p>
            <form action="<?= htmlentities($_SERVER['PHP_SELF'],
                                       ENT_QUOTES) ?>"
                  method="get">
                <input type="submit" value="try again" />
            </form>
            <?php
        }

        else if (! is_numeric($value2))
        {
            ?>
            <p id="errors"> 2nd textfield MUST contain a 
                number! </p>
            <form action="<?= htmlentities($_SERVER['PHP_SELF'],
                                       ENT_QUOTES) ?>"
                <input type="submit" value="try again" />
            </form>
            <?php
        }

        else
        {
            ?>
            <p> form's contents: </p>

            <!-- remember, we called htmlspecialchars on
                 the entered values above... -->

            <ul>
            <li> first textfield's value: <?= $value1 ?> </li>
            <li> second textfield's number 
                 multiplied by 10: <?= $value2 * 10 ?> </li>
            <li> third textfield's value: <?= $value3 ?> </li>
            </ul>

            <form action="<?= htmlentities($_SERVER['PHP_SELF'],
                                       ENT_QUOTES) ?>"
                  method="get">
                <input type="submit" value="done" />
            </form>

            <?php
        }
    }
?>