Jump to content

Subverter

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by Subverter

  1. index.html

    Give the "Text Input" a name not an ID.

           <!-- This section is for: Take a quick Godzilla survey /-->
            <div id="survey-div">
                <form id="survey-form" class="MainPgTxtBckgColor" action = "GetFormData.php" method = "post">
                    <fieldset id="survey-fieldset">
                        <legend>Take one of our quick surveys.</legend>
                        <p>
                            <label>1. Who is your <strong>favorite monster</strong> character (Godzilla related or not):</label>
                            <input name="favmonster" type = "text" value = "" />
                        </p>
                        <p>
                            <label>Press 'Submit' when you are done.</label>
                            <input type="submit" value="Submit" name="submit_button">
                        </p>
                    </fieldset>
                </form>
            </div>

     

    GetFormData.php
     Watch here how to print code output

     <?php
        // define variables and set to empty values
        $favmonsterErr = "";
        $favmonster = "";
    
        // verify that field is not empty
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            if (empty($_POST['favmonster'])) {
                echo "Favorite Monster is required";
                echo '<input type="button" style="display: block" value="Back" onclick="window.history.back()" />';
            } else {
                $favmonster = test_input($_POST['favmonster']);
                echo "You Favorite Monster is: " .$favmonster;
                echo '<input type="button" style="display: block" value="Back" onclick="window.history.back()" />';
            }
        }
    
        function test_input($data) {
            $data = trim($data);
            $data = stripslashes($data);
            $data = htmlspecialchars($data);
            if (!preg_match('/^[a-zA-Z ]*$/',$data)) {
                $data = "Only letters and white space allowed";
            }
            return $data;
        }
        ?> 

     

     

×
×
  • Create New...