Other demos in this series (for more details, go to my blog post):
  1. Test a form without attributes and the single input is not named.
  2. Test a form without attributes and the single input is named.
  3. Test a form without attributes and two named inputs - does not work!
  4. Test a form without attributes and two named inputs with a submit button - that fixes it!
  5. Test a form with "action" set to empty string (""), method is "POST", and the input is named.
  6. Test several different forms mixed with query strings in the "action"
This is what the server sees:

REQUEST_URI was /test-post-form-empty-action.php

POST was Array ( )

GET was Array ( )


This form has a submit input, an empty action (""), and uses the POST method:

<form action="" method="POST">
You can verify this by viewing the source of this page.

If you visit this page and the URL has a query string, that query string will remain when you click the submit button. Try typing some text into the input, and then click the button. You should see both GET and POST parameters if you came here with a query string, otherwise you'll just see POST parameters.

This page was created in November 2019. I tested it in Chrome. If I type in some text, and hit the button, the form submits. The $_GET array contains info if the original URL had a query string. The $_POST variable contains whatever text I typed in.

The takeaway here is that the empty action helps you retain the query string with which the user came to the page - this can be useful when sharing links. Some users will copy the URL in the address bar for sharing, and if that query string is important, you want it to remain even after a form submission. It's also useful for reloading a page. If a user submits a form using a POST, and then tries to reload the page, they'll get a question asking them if they want to re-POST the data. If the user doesn't want to re-POST, but does want to reload the page, then they can copy the URL including its query string, paste it into the browser's address bar, and hit enter to avoid the re-POST.