I build a simple webpage with embeded TinyMCE.
The HTML part:
<form method="post" action="dump.php">
<div id="main">
<div id="container_left">
<textarea id="mytextarea"></textarea>
<input id="submit" type="submit" value="submit">
</div>
<div id="show_right"></div>
</div>
</form>
The JavaScript part.
<script src="tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
height: 250,
plugins: [
"code advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
toolbar: "code insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
setup: function (editor) {
editor.on('init keydown change', function (e) {
document.getElementById('show_right').innerText = editor.getContent();
});
}
});
</script>
Now I want to print content in the TinyMCE's editor, after you click the submit button.
The dump.php
<?php
print_r($_POST);
?>
Why nothing print by dump.php?
I can send info to the dump.php via AJAX method.
1.Remove <form method="post" action="dump.php"></form> in html part.
2.Add the following js code in the JavaScript part.
<script>
function send(){
var data = tinyMCE.get('mytextarea').getContent();
var ajax = new XMLHttpRequest();
ajax.open('POST','dump.php',false);
ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
ajax.send('data='+data);
}
ob = document.getElementById("submit");
ob.addEventListener("click",send);
</script>
I have tried that it can pass content which I type in the textarea whose id is mytextarea to dump.php and dump.php can print the array properly.
My issue is how to pass content in TinyMCE's textarea to a PHP file directly instead of sending it via AJAX?
Do the work without AJAX.