$_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.
PHP $_POST array always empty upon form submission
You need to be using the name attribute, not the ID attribute. If no elements have a name attribute, no data will show up in the array.
<form action="test.php" method="post">
<input name="example" type="text" />
<input name="submit" type="submit" value="Send" />
</form>
$_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 usingcreateElement
,appendChild
and friends to add the data to the current document)
Either _POST or _FILES is empty when submitting form
It was an issue of directory vs. path.
// The folder where the images will be stored
$uploadDir = CONTENT_PATH . '/';
Should be corrected to:
// The folder where the images will be stored
$uploadDir = CONTENT_DIR . '/';
Where the global variables CONTENT_PATH and CONTENT_DIR are:
defined('CONTENT_PATH')
or define('CONTENT_PATH', realpath($_SERVER['HTTP_HOST']) . '/Shape_Search/public_html/img/content');
defined('CONTENT_DIR')
or define('CONTENT_DIR', dirname(dirname(__FILE__)) . '/public_html/img/content');
$_POST is empty, form
your fields require name attribute
<form method = "POST">
<div class = "formDiv">
<label for="name">name</label>
<input name ="name" class="name" id="name">
</div>
<div class = "button1">
<input type="submit" name="submit" value="submit">
</div>
</form>
Related Topics
Mcrypt Is Deprecated, What Is the Alternative
How to Generate in PHP All Combinations of Items in Multiple Arrays
How to Use Ajax in a Wordpress Shortcode
Facebook Graph API Not Work from 2.2 to 2.3
"Keep Me Logged In" - the Best Approach
Passing Arrays as Url Parameter
MySQL Integer Field Is Returned as String in PHP
PHP Generate File For Download Then Redirect
Preg_Match(): Compilation Failed: Invalid Range in Character Class At Offset
PHP Exec() VS System() VS Passthru()
Pdo MySQL: Use Pdo::Attr_Emulate_Prepares or Not
How to Savehtml of Domdocument Without HTML Wrapper
Accessing $_Cookie Immediately After Setcookie()
Run PHP Script as Daemon Process
Displaying HTML With Blade Shows the HTML Code
How to Get the Jquery $.Ajax Error Response Text
PHP MySQLi_Connect: Authentication Method Unknown to the Client [Caching_Sha2_Password]