I am using froala editor v2, and I need to save the form content through ajax request, so I am tried following way
HTML
<form enctype="multipart/form-data" id="composeForm" action="#" method="post">
<input type="file" name="compose_attachments[]" id="file-7" class="inputfile theme-inputfile" accept=".jpg,.jpeg,.png,.xls,.xlsx,.csv,.pdf,.ppt,.doc,.docx" multiple />
<input type="text" class="form-control inputES" placeholder="Email Subject" name="compose_subject">
<input class="autoTags" type="text" value="" data-role="tagsinput" placeholder="" name="compose_to">
<input class="autoTags" type="text" value="" data-role="tagsinput" placeholder="" name="compose_cc">
<input class="autoTags" type="text" value="" data-role="tagsinput" placeholder="" name="compose_bcc">
<textarea class="froala-editor-mail" id="composeEmailBody" name="compose_body"></textarea>
<button type="button" class="btn btn-green-bs p-lr-30 mr-10" id="SendComposedEmail">SEND</button>
</form>
JS
<script>
var editor_compose = new FroalaEditor('#composeEmailBody', {
// Set the save URL.
saveURL: `${ajaxUrl}?method=sendTestEmail`,
// HTTP request type.
saveMethod: 'POST',
saveParams: new FormData($("#composeForm")[0]),
events: {
'save.before': function () {
// Before save request is made.
showLoader(0);
},
'save.after': function () {
// After successfully save request.
showLoader(1);
},
'save.error': function () {
// Do something here.
alert("Save error;");
}
}
});
document.querySelector('#SendComposedEmail').addEventListener("click", function () {
editor_compose.save.save();
});
</script>
PHP
<?PHP
case 'sendTestEmail':
echo "<pre>";print_r($_POST);print_r($_FILES);exit;
break;
?>
OUTPUT
Array
(
)
$_POST & $_FILES are empty and only got by editor HTML value.
so, I am not able to get formData in ajax request. how to resolve it??