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.
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.
found the problem.
Apperently there is something wrong with using mysite/import, and when I changed the action to action='../import/' (instead of action='../import') it worked.
Related
I have a form with one text input field:
index.html
<form method="post" action="comment.php">
<a href="javascript:void(0)">
<div class="avatar" style="background:url('img/user4561.jpg') center/cover"></div>
</a>
<input name="comm" type="text"/>
<input type="submit" value="submit"/>
</form>
And here is comment.php in the same directory
<?php
echo $_POST["comm"];
?>
Now the most incredible event. The form data does not get submitted! I get an error:
Notice: Undefined index: comm in 192.168.0.1/comment.php on line 2
I changed comment.php like this:
<?php
if(isset($_POST["comm"])) {
echo "It is set";
} else {
echo "It is not set";
}
?>
and I get:
It is not set
So, I copied the HTML code of the form into another blank webpage. I also changed the action attribute of the form to "192.168.0.1/comment.php". Now I get
It is set
I also tried using GET instead of POST, but I am again in the same conflict.
EDIT: I removed all other files and code, except for the form and its script. The problem persists. You can now read and modify the source code. Go to files.000webhost.com. Use chatstack as the website name and 6RxOkuJ1CIkbNqxKUMGr as the password.
EDIT: I modified the code for the form above to exactly match that in the above given link. I noticed that removing the link from inside the form solves the problem. I have already done this, but this is so weird. According to this post it is totally fine to have other elements inside a <form> element. There are also other parts of my website where I have <div> elements inside a form element and the form is working fine.
What is this? Is it the server or something else?
I am pretty sure the information provided here is not enough. Feel free to ask for any additional information. There is just too much information to write in a post, and I don't know which part of it is relevant.
Open your dev-console in browser.
Go to the network tab. Now you fill in your form and submit. After your comment.php is loaded, you check for the very first row in the network tab (should be the comment.php html document).
When you click on that request it should display you, whether the request was GET or POST and also what data were sent to this document.
You can also try at comment.php var_dump($_REQUEST); to see what data were sent and how it can be accessed.
By this you can see if server all over receives any data. If yes, then you go for an other server like apache2 for testing purpose to look if bug is fixed.
That's how I would to that, but I suspect that by editing your code for the public, you accidentally withheld some information that would solve this simple problem.
It's very unlikely that web-servers like WAMP had passed the testing environment before publishing a new version allthough no data could be procesed by server
So this never happen to me before until today.
I have a login form trying to send a simple post to the action form. var_dump returns array 0 when i use post method BUT when i use method = get and var_dump the get i get all the strings.
here is my html code
<form name="mlsnavform" id="mlsnavform" action="script/mlsnavform.php" method="POST">
<input id="uname" name="uname"type="text" placeholder="Username" autocomplete="off">
<input id="loginbtn" name="loginbtn" type="submit" value="SIGN IN">
</form>
here is mlsnavform.php
<?php
var_dump($_POST);
?>
And the result of this is array(0) { }
But when i change the method from post to get, and use var_dump($_get) instead of $_post i DO get the values but ofcourse login credentials showing up in your URL address is not something i would ever want to do.
Using get fills my array with what i need tho
array(2) { ["uname"]=> string(9) "damnitphp" ["loginbtn"]=> string(7) "SIGN IN" }
This never happen to me, i've been scrolling on stack for almost 2 days now for a "posible duplicate" before i decide to make a new post but there was only 1 i found which had an answer talking about "PHPStorm" but i do not use phpstorm. I use notepad++(yes i could use sublime or atom or brackets but im so used to notepad i dont feel the need of switching to another text editor).
Anyone know any fix for this? thanks in advance!
EDIT: So today i decide to open a project i made 4months ago that always worked, but the post from that page isnt working either. So what did i do? i decided to to remove that 1 thing i added a couple of weeks ago before all these issues started.
URL REWRITE from IIS so i can remove the .phpextension
So basically this was my issue all along but so far googling around there isnt a single topic on the net where other people are talking about this. If there maybe a similar issue to this. would much appreciated if someone can comment me the link or a solution.thanks in advance.
So my issue is "$_POST" doesnt work when i have my URL Rewrite code in the webconfig. if i remove the rewrite code then the .php extension shows in the browser(which i don't want) but my $_post methods work again.
You can check the enable_post_data_reading in php.ini
From php.ini:
; Whether PHP will read the POST data.
; This option is enabled by default.
; Most likely, you won't want to disable this option globally. It causes $_POST
; and $_FILES to always be empty; the only way you will be able to read the
; POST data will be through the php://input stream wrapper. This can be useful
; to proxy requests or to process the POST data in a memory efficient fashion.
; http://php.net/enable-post-data-reading
Check if this option is uncommented and comment this with ";"
;enable_post_data_reading = Off
You probably are taking the superglobal variable names POST and GET too literal. $_GET is the parsed query string, it's independent of the HTTP method, i.e. it will always be present, even with POST requests. $_POST is the parsed HTTP body when conforming to some constraints (the content-type header has to specify either application/x-www-form-urlencoded or multipart/form-data, and I think the method really has to be "POST" - Note that when NOT conforming to the constraints, even if you'd use the POST method, you won't get any data inside $_POST.
<form name="mlsnavform" id="mlsnavform" enctype="application/x-www-form-urlencoded" action="script/mlsnavform.php" method="POST">
<input id="uname" name="uname"type="text" placeholder="Username" autocomplete="off">
<input id="loginbtn" name="loginbtn" type="submit" value="SIGN IN">
</form>
Running PhpStorm 2016.3.2, Ubuntu 16.04 with PHP7 and LAMP stack installed and tested.
I seem to have an error in PhpStorm (or somewhere else down the line), whereby clicking 'Submit' in an html form will result in a '404 not found' error, even if the form action path is valid.
I built a very simple application to demonstrate this, however it should be noted that this error has occurred every time I use an html form in PhpStorm so far, even example applications that I know have no errors in code.
The code for my form is as follows
var $form = <<< FORM
<form action='?' method="post">
<p>Enter your number </p>
<input type="text" name="formInput"
maxlength="10">
<input type="submit" name="formSubmit"
value="Submit">
</form>
FORM;
Once 'Submit' is clicked, the 404 error happens. I have tried multiple permeations of form action such as "" and even a variable set to APP_ROOT_PATH, and then just manually typing out the correct path (even a different php file) also with single and double quotes.
The reason I believe these paths to be valid is that simply by clicking in the address window from the 404 error page and hitting enter (thereby going to the path it was trying to get to) the form loads again fine.
I can't get my head around why this might be, if it was a permissions or path error surely I would not be able to access the path from the browser either?
EDIT: Looking at the source code reveals that the action is what I intended it to be. Even copying the url from there and pasting it into the browser will open the correct form. It is just when clicking 'submit' that the 404 error happens. The correct url is also in the address bar on the 404 page.
EDIT 2 : For note, the '?' action in the above code is irrelevant to the issue as the error occurs no matter what correct link I put there, be it "" or the full path.
I have a php form on my website and it works well under firefox. But whenever I tested on IE(v8 and 9), the form doesn't get sent, and it returns a "IE can't display the webpage" error.
The script is located at http://www.fitnessgrace.com/Vancouver-Personal-Trainers/Vancouver-Personal-Trainers-Contact-Fitness-Grace.htm
Any insights would be very much appreciated.
you are posting the page to http://www.FitnessGrace.com/gdform.php
and you have a hidden input
<input type="hidden" name="redirect" value="../index.html" />
after this point, I can only guess, but I think you are trying to redirect to "../index.html", and since gdform.php is already at the root directory, ../ is meaningless. I think firefox somehow understands that you've made a mistake and doesn't care, but ie doesn't understand.
I have a simple HTML form, sending a post request to a php script. In IE8, the form only works intermittently - most of the time the PHP script sees an empty $_POST variable.
Here's my code:
<html>
<head>
<title>Post test</title>
</head>
<body style="text-align: center;">
<?php
echo "<pre>".print_r($_POST, TRUE)."</pre>";
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" name="name">
<input type="hidden" name="hidden" value="moo" >
<input type="submit" value="Search" >
</form>
</body>
</html>
Sometimes the print_r gives the response you'd expect (i.e. it's populated with the data from the form), most of the time it's empty.
Not being able to use POST is a bit of a problem for web applications - anyone got any ideas what's going on, and how to fix it?
Thanks everyone for wading in on this one.
It turns out the problem lay in an Apache module I had enabled.
It's a module to allow apache to use Windows authentication to identify a user via their Windows User id - mod_auth_sspi
The effect is caused by a known bug, in the module, but with a simple extra directive this can be worked around, until a fix is added in the next update, as described here:
http://sourceforge.net/projects/mod-auth-sspi/forums/forum/550583/topic/3392037
That sounds very very bizarre. Does it happen in other versions of IE as well?
I can't tell you what the problem is, but here are my suggestions on how to diagnose it:
Print $_REQUEST rather than just $_POST, to see if the data is coming in via another method.
Use a tool like Fiddler or Wireshark to track exactly what is actually being sent by the browser.
Fiddler in particular has been very helpful for me a few times (mainly when debugging Ajax code), and will tell you exactly what was posted by the browser. If your web server is localhost, you can also use Fiddler to track what is received before PHP gets its hands on it. If not, you can use wireshark on the server if you have permissions for installing that sort of thing.
In addition to Fiddler, I would have suggested a browser-based tool like Firebug, but I don't know of one for IE that is good enough (The IE dev toolbar doesn't give you details of request and response data, as far as I know).
I'm suspicious that when the script is telling you that $_POST is empty, you did not actually POST the form. You can check by adding print($_SERVER['REQUEST_METHOD']); after your print_r($_POST);
If you are posting a file some of the time (i.e. with a file input) then make sure you set enctype="multipart/form-data" in your <form> element.
Have you checked the generated html? Is it possible that echo $_SERVER['PHP_SELF'] isn't producing the output you're after, which messes up the form html, which messes up the POST?