简体   繁体   English

为什么此表单提交未按预期工作

[英]Why this form submit isn't working as expected

I have this code in test.php . 我在test.php有此代码。

  • When I access the script just by typing it, I want to see just the form 当我仅通过键入脚本来访问脚本时,我只想查看表单
  • but when I click the form submit button, the next time the page loads, I want to see the form and some comment that says that the form has been submitted. 但是,当我单击表单提交按钮时,下一次页面加载时,我想查看该表单以及一些说明该表单已提交的注释。

For some reason, even when I click submit, I don't get the message that it's posting. 出于某种原因,即使单击“提交”,也不会收到它正在发布的消息。 Anyone can explain why? 任何人都可以解释为什么? and how can I get it to work. 以及如何使它工作。

<body>
    <form action="" method="post">
        <input type="text" id="inp" />
        <input type="submit" value="submit" />      
    </form>

    <?php
    if (isset($_POST['submit'])) {
        echo "posting";
    }

    ?>
</body>

给输入一个名字:

<input type="submit" name="submit" value="submit" /> 
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    echo "posting";
}

Try this: 尝试这个:

<body>
    <form action="" method="post">
        <input type="text" id="inp" />
<input type='hidden' name='submit' value=''>
        <input type="submit" value="submit" />      
    </form>

    <?php
    if (isset($_POST['submit'])) {
        echo "posting";
    }

    ?>
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM