显示带有$ _POST的表单?

时间:2018-06-27 19:42:31

标签: php html

我一直在尝试填写表格以显示在表格旁边。 我尝试使用if语句来执行此操作,但是没有运气。

我也尝试只做print_r,但是确实可以,但是我希望它在您点击提交显示后就显示出来。

到目前为止,这里是我的代码!

<form action="phptest1.php" method="POST">
<fieldset>
    <legend>Inloggegevens:</legend>
    <label for="naam">Gebruikersnaam:</label>
    <input type="text" name="naam" id="naam">
    <label for="wachtwoord">Wachtwoord:</label>
    <input type="password" name="wachtwoord" id="wachtwoord"><br>
    <label for="man">Man</label><br>
    <input type="radio" name="gender" value="male"><br>
    <label for="for">Vrouw</label><br>
    <input type="radio" name="gender" value="female"><br>
    <label for="checkbox">Ik heb de algemene voorwaarden gelezen.</label><br>
    <input type="checkbox" name="conditions" value="agree">
    <textarea name="commentaar" rows="4" cols="40"
    placeholder="Schrijf hier uw commentaar…"></textarea>
    <select name="land">
        <option value="nl">Nederland</option>
        <option value="be">Belgi&euml;</option>
        <option value="de">Duitsland</option>
        <option value="fr">Frankrijk</option>
    </select>
</fieldset>

    <input type="reset"><br>
    <input for="submit" type="submit">

<?php
if (isset($_POST['submit']))
{
    echo '<h1>'.$_POST['naam'].'</h1>';
    echo '<br><br>';
    echo $_POST['wachtwoord'];
    echo '<br><br>';
    echo $_POST["gender"];
    echo '<br><br>';
    echo $_POST["land"];
    echo '<br><br>';

    } else {
    echo 'U bent nog niet ingelogd.';
    }

    ?>

3 个答案:

答案 0 :(得分:2)

$_POST的索引由input元素的名称填充。由于您没有名为submit的元素,因此永远不会遇到isset。要解决这个问题,请给它起个名字。

<input for="submit" type="submit" name="submit">

答案 1 :(得分:0)

代替

action="phptest.php"

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

您可以使用

action=""

if($_POST)

action=""将确保帖子再次发送到当前页面/文件。 if($_POST)仍确保if语句中的代码仅在发布页面时运行。您可以使用isset($_POST['submit']),但是您的“提交”按钮没有名称submit,因此永远不会有$_POST['submit']

答案 2 :(得分:0)

将提交按钮替换为以下内容:

<input type="submit" name="submit" value="submit"/>

并通过从操作中删除phptest1.php或仅使用以下命令来确保帖子已提交到同一页面:

<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">