I want to POST my form using PHP, but for some reason seems impossible, whatever I try to post the message is always empty.
I tried this code:
HTML
<div class="message-container">
<form id="imageForm" name="form" action="/requests/post_message.php" method="POST" enctype="multipart/form-data">
<div class="message-form-content">
<div class="message-form-header">
<div class="message-form-user"></div>
<div class="message-form-private"></div>
<div class="message-loader" id="post-loader" style="visibility: hidden"><div class="preloader"></div></div>
</div>
<div class="message-form-inner">
<textarea id="post" class="message-form" placeholder="message_form" name="message"></textarea>
</div>
<div class="selected-files"><span id="queued-files">0</span> Files selected</div>
<div class="message-form-input"><input type="text" name="value" id="form-value"></div>
<div type="button" name="action" class="message-btn button-active" value="Post"><a onclick="startUpload()">Post</a></div>
</div>
<iframe id="my_iframe" name="my_iframe" src="" style="display: none"></iframe>
</form>
</div>
JavaScript
function startUpload() {
document.getElementById("imageForm").target = "my_iframe";
document.getElementById("imageForm").submit();
alert($("#imageForm").serialize()); //for debug
document.getElementById("post-loader").style.visibility = "visible";
}
post_message.php
<?php
include("../includes/config.php");
session_start();
print_r($_POST['message']);
From network console I double checked the request and it's correct, I can see POST with status 200.
However when I write into the textarea and click on the Post button, the JS alert show me the message correctly instead the print_r of my PHP is empty, what's wrong with my form?
$_GETinstead of $_POST.