isset($_POST['Submit'] 提交后未设置

isset($_POST['Submit'] not set after submit

我知道这似乎是一个常见问题,但我搜索了很多,但没有任何帮助。我有以下代码,在提交时,除了重新加载页面外没有任何反应。我尝试使用 enctype 和不使用 <input type=button ...><button ...> 但我从来没有得到回声...

<?php

if (isset($_POST['Submit']) && !empty($_POST['Submit'])){
  echo 'It works';
} else {
?>

<form method="post" enctype="multipart/form-data" action="">
    <div class="form-group">
        <label for="name" class="control-label">Name</label>
        <input name="name" type="text" class="form-control" id="name" placeholder="Name"
               aria-describedby="helpBlock"
               oninvalid="this.setCustomValidity('Bitte tragen Sie Ihren Namen ein.')"
               oninput="setCustomValidity('')"
               required>
    </div>

    <!-- multiple other form-groups like the first one -->

    <div class="form-group">
        <input name="Submit" type="submit" class="btn btn-default" value="Abschicken">
    </div>
    <div id="helpBlock">* Alle Felder sind Pflichtfelder.</div>
</form>
<?php } ?>

更新:

  1. 我通过 xampp
  2. 在本地主机上 运行 此代码
  3. 删除!empty($_POST['Submit'])也无济于事
  4. 是的,它是一个 .php 文件

更新:

如果我尝试输入

foreach ($_POST as $key => $value) { echo 'index key ' . $key . ' value ' . $value . '<br>';}

页面上没有显示任何内容 - 所以我假设没有设置 $_POST 变量...谁能告诉我为什么?

我解决了这个问题:问题是,由于 URL localhost[...]/test.php?nav=kontakt 表单总是尝试执行 GET 请求。现在我必须使用静态页面而不是带有参数

test.php