PHP表单不显示反馈

时间:2016-02-22 12:01:57

标签: php

我在PHP中创建一个流程表单,我正在尝试显示反馈,但它不想显示。我的代码是:

<html>
    <head>
        <style type="text/css">
            .error{color: #FF0000;}
        </style>
    </head>
    <body>
        <h1>Customer Feedback</h1>
        <p1>Please tell us what you think</p1><br><br>

        <?PHP
            $name = trim($_POST[fullname]);
            $email = trim($_POST[email]);
            $text = trim($_POST[feedback]);
        ?>

        <form method='POST' action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>' >
            <p1>Your name:</p1><br>
            <input type="text" name="fullname" value="<?php echo $fullname; ?>" required><br><br>
            <p1>Your email address:</p1><br>
            <input type="text" name="email" value="<?php echo $email; ?>" required><br><br>
            <p1>Your feedback:</p1><br>
            <textarea rows="5"  cols="50" name="feedback"><?php echo nl2br($text);?></textarea>
            <textarea><?php echo $text;?></textarea><br><br>
            <input type="submit" Value="Send Feedback"><br><br>
        </form> 

        <?php
            if(isset($_POST[fullname]) && $_POST[fullname] != "" && !empty($_POST[fullname])) {
                echo "Hi " . $name . ".<br>";
            }
            else{
                echo "Please enter a name....";
            }

            if(isset($_POST[email]) && $_POST[email] != "" && !empty($_POST[email]) {
                echo "Your email is " . $email . ".<br>";   
            }
            else{
                echo "Please enter a email address.";
            }

            if(isset($_POST[feedback]) && $_POST[feedback] != "") {
                echo "Your feedback is:" . $feedback . "<br>";
            }
            else{
                echo "No feedback.";
            }
        ?>
    </body>
</html>

当我运行该页面时,它显示名称,电子邮件和“您的反馈是:”,但不是输入到textarea的反馈。

修改 我想在文本框周围使用nl2br()函数。

2 个答案:

答案 0 :(得分:3)

将以下行更改为:

echo "Your feedback is:" . $text . "<br>";

因为您从未为$feedback变量赋值。

答案 1 :(得分:0)

您的代码有太多错误我已经纠正过,请填写下面的工作代码:

<html>
    <head>
        <style type="text/css">
            .error{color: #FF0000;}
        </style>
    </head>
    <body>
        <h1>Customer Feedback</h1>
        <p1>Please tell us what you think</p1><br><br>

        <?PHP
            $name = trim($_POST[fullname]);
            $email = trim($_POST[email]);
            $text = trim($_POST[feedback]);
        ?>

        <form method='POST' action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>' >
            <p1>Your name:</p1><br>
            <input type="text" name="fullname" value="<?php echo $fullname; ?>" required><br><br>
            <p1>Your email address:</p1><br>
            <input type="text" name="email" value="<?php echo $email; ?>" required><br><br>
            <p1>Your feedback:</p1><br>
            <textarea rows="5"  cols="50" name="feedback"><?php echo nl2br($text);?></textarea>
            <textarea><?php echo $text;?></textarea><br><br>
            <input type="submit" Value="Send Feedback"><br><br>
        </form> 

        <?php
            if(isset($_POST['fullname']) && $_POST['fullname'] != "" && !empty($_POST['fullname'])) {
                echo "Hi " . $name . ".<br>";
            }
            else{
                echo "Please enter a name....";
            }

            if($_POST['email'] && $_POST['email'] != "" && $_POST['email']) {
                echo "Your email is " . $email . ".<br>";   
            }
            else{
                echo "Please enter a email address.";
            }

            if(isset($_POST['feedback']) && $_POST['feedback'] != "") {
                echo "Your feedback is:" . $_POST['feedback'] . "<br>";
            }
            else{
                echo "No feedback.";
            }
        ?>
    </body>
</html>