PHP - Form without action keeps GET data. Form with action (same url) don't
<p>Kind of confused.Let me explain an example situation.</p>

<p>I have a form at delete.php (plain PHP, no framework) that receives a parameter through http get</p>

<p>When I send the form I've always thought that GET values are going to be lost therefore, If I want to keep those values I must use input type="hidden" , sessions or any other mechanism.</p>

<p>But using PHP 7.0.8, Apache 2.4(for sure it's not a version issue just wanted to let you know) I've realized the following:</p>

<p>a) If the action of the form is set to delete.php (the same url) GET values are lost once the form is submitted. As expected</p>

<p>b) If the action of the form is NOT set then data are sent to delete.php (as expected) but GET values are kept.</p>

<p>I don't know why and I can't find an explanation in any docs or http espec.</p>

<p>Does anybody know where is this situation explained?</p>

<p>Here's the code</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;title&gt;GET / POST TEST&lt;/title&gt;
    &lt;link rel="stylesheet" type="text/css" href=" "&gt;
  &lt;/head&gt;
  &lt;body&gt;

      &lt;form method="post" action="get_post_test.php"&gt;
        Name&lt;input type="text" name="name" required&gt;&lt;br&gt;
        LastName&lt;input type="text" name="lastname" required&gt;&lt;br&gt;
        &lt;p&gt;
          &lt;input type="submit"&gt;
        &lt;/p&gt;
      &lt;/form&gt;

      &lt;?php

          if(isset($_GET['id'])) {
            echo "TENGO GET";
            var_dump($_GET);
          }

          if (isset($_POST['name'])) {
            echo "TENGO POST";
            var_dump($_POST);
          }
      ?&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I'm getting $_GET['id'] through a link and if:</p>

<p>a) action="get_post_test.php" then $_GET['id'] is lost when form submitting (as I expected because get_post_test.php is the name of the current file)</p>

<p>b) If I don't set any action $_GET['id'] still is available when submitting ????????</p>

<p>Kind regards.</p>