php $_POST array empty upon form submission php $_POST array empty upon form submission arrays arrays

php $_POST array empty upon form submission


When using JSON content-type the $_POST array will not populate (only with multi-part forms I believe)

Here is how I correct the issue:

$_POST = json_decode(file_get_contents("php://input"), true);


Here's another possible cause -- my form was submitting to domain.com without the WWW. and I had set up an automatic redirect to add the "WWW." The $_POST array was getting emptied in the process. So to fix it all I had to do was submit to www.domain.com


I had a similar problem. Turned out to be a simple fix. In the form I had

<form action="directory" method="post">

where directory was the name of... the directory. My POST array was totally empty. When I looked at the url in my browser, it was displayed with a forward slash on the end.

Adding the forward slash to the end of my action did the trick -

<form action="directory/" method="post">

My $_POST array was full again!