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

<!--
    responding to refactored three-value-form2.php

    by: Sharon Tuttle
    last modified: 2016-04-11
-->

<head>  
    <title> responding to three-value-form2.php </title>
    <meta charset="utf-8" />

    <link href="http://users.humboldt.edu/smtuttle/styles/normalize.css" 
          type="text/css" rel="stylesheet" />
    <link href="three-value-form.css"
          type="text/css" rel="stylesheet" />
</head> 

<body> 
    <h1> quick'n'sleazy response to three-value-form2.php </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="three-value-form2.php"
                  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="three-value-form2.php"
                  method="get">
                <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="three-value-form2.php"
                  method="get">
                <input type="submit" value="done" />
            </form>

            <?php
        }

        require_once("328footer-better.html");
    ?>

</body>
</html>