PhpStorm - strange 404 error when using html forms - php

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.

Related

$_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.
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

Why is my form using GET instead of POST?

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.

After select file check that user change file name before upload

Let's say I want to upload a csv file to PHP. I noticed in Chrome if I select, for example, "test.csv" in the file selection box,
if I rename the file locally to "test1.csv",
then upon submitting the form to PHP, I see an error page:
ERR_FILE_NOT_FOUND
I want to catch this error and show a friendly error message instead.
The issue you described has nothing to do with PHP or jQuery. I have isolated the issue you have described down to:
<form action="http://www.google.com" method="POST" enctype="multipart/form-data">
<p>Select a file, for example z.txt, then before clicking submit,
rename the file locally so the file picked is invalid, such as zz.txt,
then submit to get an error in chrome.</p>
<input type="file" name="myFile">
<input type="submit" />
</form>
Yes, it doesn't even matter where the form sends to. Chrome will error if the file doesn't exist before it tries to send. Firefox, however, will submit the form as usual. This is an issue with chrome. You can, however, adjust chrome to hide network messages:
Suppress "Failed to load resource: net::ERR_FILE_NOT_FOUND" in Chrome Packaged App

PHP Validation and Site Redirection

I have looked around for "PHP validation and redirection" but so far they don't work me because I cannot execute PHP scripts inside a HTML page because my website hosting does not give me access to the apache config httpd file. I can add handlers but I don't think that helps me. Here's what I'm trying to do:
User inputs some stuff including a valid email address
PHP creates a json string and save it on the server (works)
Write an email to the user confirming what they've entered (works)
Re-direct after the submit which is from the following code:
<form method=POST action="go.php">
<input type="submit" value="Submit" />
</form>
If the user has entered anything invalid (email, name...) the PHP script should return the user to the previous page with a red * beside the field that's invalid.
My question is, how can I do that without putting PHP inside the html?

php form doesn't work on IE

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.

Categories