I want to send textarea value in php Suneditor
PHP code
if($_POST["submit"]){
$content = $_POST["txtEditor"];
echo $content;
}
Html Code
<form action="" method="post" >
<textarea id="txtEditor" name="txtEditor" style="display:none;"></textarea>
<input type="submit" name="submit" class="submit">
</form>
Javascript
$(document).ready(function() {
$("#txtEditor").Editor();
$('form').submit(function () {
$('#txtEditor').val($('#txtEditor').Editor('getText'));
});
$('#txtEditor').Editor('setText', $('#txtEditor').val());
});
suneditor.create('txtEditor', {
buttonList: [
['undo', 'redo', 'removeFormat'],
[align, font, fontSize, fontColor, hiliteColor],
[horizontalRule, image, template]
],
})
Editor working perfectly.
Where I did go wrong?
full code
const description = SUNEDITOR.create((document.getElementById('description')),{
buttonList: [
['undo', 'redo'],
['bold', 'underline', 'italic'],
['removeFormat'],
['outdent', 'indent'],
['align', 'list'],
['table'],
['fullScreen', 'showBlocks']
],
lang: SUNEDITOR_LANG['pl']
});
$(window).click(function() {
document.getElementById('description').value = description.getContents();
});
You must send values from suneditor to textarea, you can do that:
$(window).click(function() {
document.getElementById('txtEditor').value = txtEditor.getContents();
});
You need isset function in if condition otherwise it will throw an error.
if(isset($_POST["submit"])){
$content = $_POST["txtEditor"];
echo $content;
}
No need to write any js code for this, just put your text/content between textarea tag just like:
<textarea id="txtEditor" name="txtEditor" style="display:none;">Here is your text</textarea>
OR
<textarea id="txtEditor" name="txtEditor" style="display:none;">
<?= $content; ?>
</textarea>
// Gets the suneditor's context object. Contains settings, plugins, and cached element objects
editor.getContext();
// Gets the contents of the suneditor
// onlyContents {Boolean}: Return only the contents of the body without headers when the "fullPage" option is true
editor.getContents(onlyContents: Boolean);
// Gets only the text of the suneditor contents
editor.getText();
// Change the contents of the suneditor
editor.setContents('set contents');
You just need to run the instance.save()
method.
const instance = SUNEDITOR.create();
instance.save()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.