Wais Kamal
Wais Kamal

Reputation: 6180

$_POST request not being handled by the server

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.

Upvotes: 0

Views: 339

Answers (1)

saladzic
saladzic

Reputation: 56

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

Upvotes: 2

Related Questions