$_Post Is Empty After Form Submit

$_POST is empty after form submit

Add names to the input types like

<input type="text" id="inputLastname" name="inputLastname" placeholder="Last name">

Now check the $_POST variable.

POST data after HTML form submit is empty, request type is POST though

Your input fields does not have any "name" attribute.

Your input has to look like this :

<input type="number" name="amount" class="form-control" id="amount" placeholder="1000">

$_POST is empty/null after form submission

Firstly, data is an array. Hence form.append(data) will stringify the array and append it in the HTML as text. It is not adding any data to the request sent to the server.

Secondly, the form has an id of id-form yet the jQuery selects: $('#ids-form').

Thirdly, your $_POST is empty because the input in the HTML has no name attribute.

<form method="post" id="id-form" class="hidden">
<input type="hidden" id="ids" name="ids" value="" />
</form>

Once you've addressed those issues, your logic will work fine.

$_POST array empty in php after submission of a form using a formData

First, you call fetch which makes a POST request

When you get a response, you log the response object (which doesn't hold anything all that useful, in particular the body of the response will show up as a readable stream and not a string).

That response does show array(1) { ["mode"]=> string(5) "basic" } Array ( [mode] => basic ) basic though, you can see it using the Network tab of the browser's developer tools.

After logging the response you set location.replace(response["url"]); which makes a GET request (to the same URL) and navigates the browser to it.


The GET request is a different request and does not have the request body from the POST request from it.

Since it is a different request, it gets a different response and now $_POST is an empty array.


If you want to navigate to the response then get rid of the JavaScript. Just make the POST request with the form and let the browser render the resulting page.

If you want to use Ajax to make the request then:

  • Don't immediately navigate away from the page
  • Do something useful with the response (starting by calling response.text() to get the data out of the response body and then perhaps using createElement, appendChild and friends to add the data to the current document)

$_POST empty after form submit

I figured it out. It is a problem with htaccess rules written by Wordpress on the root directory. When I switched the form action to point to index.php instead of just the directory, it worked like a charm.

i.e.

  <form action="http://mywebsite.com/app/index.php" method="post">

was the change I made that fixed it.

POST/GET array is empty, after form submit

Okay guys, I've found the error!

Before I sent the value I validated the data with jQuery inside the submit function.

$("#loginModal").submit(function(){
...

The problem is that I've disabled the form before submitting it because I wanted to make some precautionary measure to the user won't be able to do anything until the server not respond.

(e.g.: long waiting time if the connection is slow)

...
$('#loginModalDiv *').prop('disabled',true);
$('#footerLogin').hide();
return true;}

When I cut the last two line out before the return, (so the form stay enabled) the submit function became capable to send the data from the input fields.

Conclusion:
So,... for everybody who don't know (like me before), the POST and GET method not send any data from a disabled part(like a < div >) of a form.
Hmmm... good to know! :)



Related Topics



Leave a reply



Submit