单击提交按钮后没有任何反应

时间:2015-10-20 21:25:52

标签: php forms

我无法弄清楚我在代码中错过了什么。我if if声明正在工作,因为我可以看到我的表单,并在提交后我想在标签后看到消息。我怎么知道提交按钮是否响应。

 <?php

$output_form = true;

$fname = "";
$lname = "";
$address1 ="";
$address2 ="";
$city = "";
$state = "";
$zipcode = "";

if (isset($_POST['submit'])) { 

print_r($_POST);

    $fname = trim($_POST["firstName"]);
    $lname = trim($_POST['lastName']);
    $address1 = trim($_POST['address1']);
    $address2 = trim($_POST['address2']);
    $city = trim($_POST['city']);
    $state = trim($_POST['state']);
    $zipcode = trim($_POST['zipcode']);

}

?>
<!DOCTYPE html>
<html>
    <head>
        <title>Assignment 3 </title>
        <link rel="stylesheet" type="text/css" href="style.css">

    </head>
    <body>

        <?php 
        if ($output_form) {
        ?>

        <h1>Enter your information</h1>

        <form name="userform" action="<?= $_SERVER['PHP_SELF'] ?>" method="post">

            <p>First Name: <input name="firstName" type="text" value="<?= $fname ?>"></p>
            <p>Last Name: <input name="lastName" type="text" value="<?= $lname ?>"></p>
            <p>Address 1: <input name="address1" type="text" value="<?= $address1 ?>"></p>
            <p>Address 2: <input name="address2" value="<?= $address2 ?>" type="text" ></p>
            <p>City: <input name="city" type="text" value="<?= $city ?>"></p>
            <p>State: <input name="state" type="text" value="<?= $state ?>"></p>
            <p>Zip Code: <input name="zipcode" type="number" value="<?= $zipcode ?>"></p>
            <input class="button" name="submit" type="button" value="Button">
        </form>
        <?php
            } else {

        ?>
                <h2>Your information is:</h2>
                <p class="result">
                Name: <?= $fname.' '.$lname ?><br>
                Street Address: <?= $address1 ?><br>
                City, State: <?=$city.' '.$state ?>
                </p>

        <?php
        }
        ?>

    </body>
</html>

1 个答案:

答案 0 :(得分:7)

提交输入类型

<input class="button" name="submit" type="button" value="Button">

应该是

<input class="button" name="submit" type="submit" value="Button">