Search code examples
phphtmlphpstorm

PhpStorm: Simple PHP form not posting


I've looked at several examples and have even copied solutions; no matter what I do, my HTML data within the form will not post.

The most typical solution on SO for users that were stuck was to include the name attribute, but I've had that since my first attempt.

Here is my HTML:

<form style="color:red;" action="test.php" method="post">
    Name: <input style="color:blue;" type="text" name="formName"><br>
    E-mail: <input style="color:blue;" type="text" name="formEmail"><br>
    <input type="submit">
</form>

Below is a snapshot of what the page looks like.

enter image description here

Here is the code for test.php

<html>
<body>

Welcome <?php echo $_POST["formName"]; ?><br>
Your email address is: <?php echo $_POST["formEmail"]; ?>

</body>
</html>

Below is a picture of data I've filled in.

enter image description here

And the resulting page when I click submit.

enter image description here

It's been years since I've used PHP; I don't remember it being this complicated so I assume I'm either doing something wrong or something is wrong with my ini file? Thanks.


EDIT: Here are some suggestions that I've tried:

  • "Try putting <?php phpinfo(); ?> into a test .php" It worked successfully, as can be seen below. enter image description here

  • "What happens when you var_dump($_POST)?" The only thing printed to the screen is array(0) { }

  • "How are you accessing this? as http://localhost/file.xxx or as file:///file.xxx?" This actually helped narrow down the problem! As stated before, I've tried testing this in two ways; through PhpStorm (which deploys in a localhost environment) and through my server. I screwed up with the server method and wasn't running it through localhost; once I fixed this, the PHP script works on the server as expected! So now I can narrow it down to the issue being specifically with my PhpStorm environment, which runs the scripts in localhost. Please keep in mind that I've tried all suggestions with both the server and PhpStorm, so that means that I did try <?php phpinfo(); ?> in PhpStorm and it worked as expected. Because the server method works fine, it's possible my set up, .ini, and/or php install on my machine is bad.


Solution

  • This is actually a well known issue with PhpStorm. You can follow this guide, PHPstorm 10.0.3 Error 502 Bad Gateway (Due to JavaVM?) and will find that it fixes this problem (as it did for me). As the author states there, "You are using PhpStorm's own built-in web server, which has some issues right now (especially with POST requests, e.g. WEB-17317).

    Essentially, what I did is follow the steps on this page: https://confluence.jetbrains.com/display/PhpStorm/Deploying+PHP+applications+with+PhpStorm

    A great start is to configure your project to deploy on your server.

    Tools -> Deployment -> Configuration