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
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.
On our website, sometimes $_POST is relayed empty to the action pages.
This happens for roughly about %1-2 of the forms submitted on a daily basis. This is about 50-100 corrupt form submissions per day currently.
We are certain the data is there on the initial page. We tried sending the same data with $_POST and $_GET at the same time with the exact same values. $_GET reaches the action page all the time, but $_POST can arrive empty.
Often times, this error happens to Webkit besed browsers. Also mobile phone browser seem to be more prone to this.
IE browsers experience this less than the Webkit browsers.
And very rarely it happens to Firefox as well.
Current configuration is like this:
PHP Version 5.2.15
Centos 5
Apache 2.2.3
One thing we are discussing is to upgrade our PHP to 5.3.x.
Does that sound like a reasonable try?
Any suggestions on how we can try to debug this?
UPDATE:
Submission form is as follows:
<form action="submit.php?receiver_user_id=<?php echo $_SESSION['receiver_user_id'];?>&sender_user_id=<?php echo $_SESSION['user_id']; ?>" method="post">
<textarea name="message_text" ></textarea>
<input type="hidden" name="receiver_user_id" value="<?php echo $_SESSION['receiver_user_id'];?>
<input type="hidden" name="sender_user_id" value="<?php echo $_SESSION['user_id']; ?>
<input type="image" name="submit" src="submit.png" value="submit"/>
</form>
Could it be that some sort of input to the form makes the sending fail, or, assuming you judge the 1-2% by empty database entries, makes the storing fail, respectively?
[edit] That sounds stupid... What I meant was, if you have a loop submitting the form 1000 times with the same values, does 1-2% still go empty, or could it be up to what is sent, that the form goes empty?
Adding
<?php header("Connection: close"); ?>
cleared the problem on our end. Apparently this relates to keep-alive and IE. You can read more about it here:
Why does Internet Explorer not send HTTP post body on Ajax call after failure?
I've created an upload script in php that takes a file, resizes it, and creates a cropped square thumbnail. The script itself seems to work fine.
However, when I tried to upload an image through Firefox, on clicking the submit button the browser shows the loading animation, but it never calls the script, it just stays on the current page. If don’t upload an image, then the script can be found and is run.
I tried in safari, and I don’t get the same problem, I can upload an image from the form, it will process it and take me the correct page.
I’ve tired just calling a basic script from the form, it just prints out the $_POST and $_FILES, and I get the same result, if an image is present, it won’t get to the script, if no image is present, it runs fine.
I’m just wondering if anyone has any idea what’s going on?
=Update=
Okay, so I’ve still got this problem, I seem to think I’ve found out what’s causing it then, but then I find something that contradicts it completely.
At the moment, I’ve noticed that I can successfully upload after I clear my Firefox cache, but I can only upload one image, then when I try to upload another, I can’t, it just resets the connection after "Loading..." for a bit.
Also, I’ve noticed that I can Ctrl+F5 a few times and get another upload through.
Although there are ways around this, I don’t want to have a form that requires users to clear cookies or refresh every time they need to upload. And as I’ve mentioned before, this error does not occur in IE/Opera/Safari/Chrome.
It seems like Firefox is storing something, I’m not sure what.
Any help would be gratefully appreciated.
If it helps here is the code I’m using.
The HTML Form
<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
<label for="file">Choose a file to upload</label>
<input id="file" name="file" type="file" /><br />
<input type="submit" value="Upload File" name="submit" />
And the PHP:
if (isset($_POST['submit'])) {
echo "Processing...<br/>";
if (isset($_FILES['file']['name'])) {
$file_array = $_FILES['file'];
echo "Uploading...";
upload File($file_array);
echo "...Done";
}
}
The echos are for me to see what’s going on. If none of them are actually being output. So for some reason the form is not being submitted. Which is why it’s not getting to the script. I’ve no idea why though. I’ve got no CSS, or JavaScript errors.
== Update ==
Okay I’ve being trying some more things and still no luck, the HTML, CSS and JavaScript is all valid. I’ve done an IIS Reset, I’ve recreated my Firefox profile. And still now luck.
I was testing it again, and this time I stopped it in the middle of loading (before the connection was reset) and then tried to go to a different page of the website, and the freezing continued, it would still say "Loading..." and "Waiting for localhost...". Not really sure what to make of that, is it some settings that I have? But then why doesn’t it affect other browsers?
== Update ==
As I mentioned below, it seems that AVG Linkscanner/Active surf shield seems to causing this issue, and there are many reports of others having similar problems with it. I updated from AVG Free v9.0.733 to v9.0.790 and I STILL have the same problem. I’m going to browse the AVG support forums and maybe post something over there since it seems to be an AVG issue.
If anyone does have any more insight, please post below. It’s much appreciated :)
Okay, im getting somewhere with this, you may think this is just a stupid mistake but read on.
If i dont have the < html >< body >..etc tags and just have..
<form enctype="multipart/form-data" action="up.php" method="POST">
<label for="file">Choose a file to upload</label>
<input id="file" name="file" type="file" /><br />
<input type="submit" value="Upload File" name="submit" />
</form>
Then i get this issue, where firefox will hang, on form submission.
If i have the correct tags like..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body >
<form enctype="multipart/form-data" action="up.php" method="POST">
<label for="file">Choose a file to upload</label>
<input id="file" name="file" type="file" /><br />
<input type="submit" value="Upload File" name="submit" />
</form>
</body>
</html>
Then it seems that this works. Now this looks simple, but i build my pages up dynamically so i just have one file that contains just the form code that gets included in the page.
Thats as far as ive got, althought having the form code in a separate file should make no difference since its all put together server side.
Sometimes, relative paths are perceived differently by different browsers, not that sure actually but try to specify current directory by prefixing path with ./, eg:
$target_path = "./public/photos/";
Rest of the code looks fine to me.
Just in case you are using the latest FF 3.6 I'm experiencing exactly the same problem, Any form loading a big file (1MB it's enought) seem to block FF upload.
On IE7/Safari/Opera it works.
Then when you right click in FF and view source, it should look exactly like it does in your code above (below "If i have the correct tags like..").
From the xhtml 1.0 specification
HTML 4 defined the name attribute for
the elements a, applet, form, frame,
iframe, img, and map. HTML 4 also
introduced the id attribute. Both of
these attributes are designed to be
used as fragment identifiers.
In XML, fragment identifiers are of
type ID, and there can only be a
single attribute of type ID per
element. Therefore, in XHTML 1.0 the
id attribute is defined to be of type
ID. In order to ensure that XHTML 1.0
documents are well-structured XML
documents, XHTML 1.0 documents MUST
use the id attribute when defining
fragment identifiers on the elements
listed above.
Maybe adding an id to the form could fix your problem.
Maybe shomething wrong with if (isset($_POST['submit'])) { and the variable $_POST['submit'] is not included by FireFox?
<pre>
<?PHP
print_r($_POST);
?>
</pre>
This isn't going to help you much but I am having EXACTLY the same problem. I have even re-installed FF, cleared cache, stripped the code right down (to a very simple form without validation and with all PHP stripped out - both on load and on post back). I have the problem in FF 3.6.13 and have tested against current versions of Safari(win), Chrome, Opera and IE where the code all works perfectly. My code validates as strict XHTML and all the suggestions above are already in there... what's more I am using my local (on the same computer) web site.
MANY thanks for pointing me towards AVG Link scanner... disabling it does fix the problem but that still leaves me thinking FF has a bug as "all" other browsers play nicely with the AVG Link scanner on.
I'm tying to send POST data from one site to another (both sites have been developed by us).
The problem is that the POST variables are not available if the page is requested from another domain.
Even if I test it locally, but specify the complete url, the POST data is gone.
So, this will work:
<form method="POST" action="test.php">
But this will not:
<form method="POST" action="http://example.com/test.php">
Here is the HTML for the page:
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="http://example.com/test.php">
<input type="text" name="request" value="" id="" />
<input type="submit" value="" id="" />
</form>
</body>
</html>
After the comments I got that this should work, I tested it on another server and there everything worked fine indeed. This might have something to do with the fact on the first server https is enabled. But if this is the case, I find it strange that I do get information back but that just the POST data has gone missing.
What you have should work fine - forms came before the same-origin policy - you're allowed to submit to different domains.
If I were to hazard a guess, I'd say there's a 301 or 302 redirect getting in there somehow? Follow the HTTP headers with Firebug for example to be sure.
As others have said, there should be no problem doing this. I would suggest replacing your test.php script with something simple, like this
<?php
echo "<pre>";
var_dump($_POST);
echo "</pre>";
You should find it works, which means the blame lies somewhere in the "real" script...
Maybe also a timesaver:
If you POST to domain.com make sure it doesn't get redirected to www.domain.com.
The redirect doesn't take the POST variables into account , only GETvariables.
If it does get redirected to the www.domain.com add the www. in your POST-action
Thank you. I too found out that redirection to www and https was blocking the performance of my $_POST request.
By changing my action to include https://www.
I fixed my problem.
Thank you