Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my form using GET instead of POST?

Tags:

forms

php

When I try to submit a form from mysite/form to mysite/import using this form:

<form action="../import" method="POST">
    <input type="text" name="hidden" value="hi">
    <input type="submit">
</form>

The import site doesn't seem to recieve the post. I get redirected to the import site, but the data doesn't seem to be there. When checking I discovered this:

var_dump($_SERVER['REQUEST_METHOD']) gives string(3) "GET"

var_dump($_POST) gives array(0) {}

var_dump($_REQUEST) gives array(0) {}

When using the same form from the import site, everything works, and when I use the form page to some random other page, it also works. I've already tried to add method='POST' to everything, or adding formmethod="post" formaction="../import" to the submit button, but nothing works.


1 Answers

My guess is that you have an intermediate redirect. There's nothing wrong with your code at first glance. Turn on developer tools in your browser (make sure the log is preserved so that it doesn't clear when the browser navigates to a new page), and watch the network activity. (You can also use a tool like Fiddler to do this). I'll bet you see a POST followed by a GET redirect to the final page.

The fact that the exact same code works on another site might indicate an .htaccess file or something in play.

like image 68
jhilgeman Avatar answered Oct 18 '25 06:10

jhilgeman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!