[英]How to send value from suneditor textarea in php?
I want to send textarea value in php Suneditor我想在 php Suneditor 中发送 textarea 值
PHP code PHP代码
if($_POST["submit"]){
$content = $_POST["txtEditor"];
echo $content;
}
Html Code html代码
<form action="" method="post" >
<textarea id="txtEditor" name="txtEditor" style="display:none;"></textarea>
<input type="submit" name="submit" class="submit">
</form>
Javascript 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:您必须将值从 suneditor 发送到 textarea,您可以这样做:
$(window).click(function() {
document.getElementById('txtEditor').value = txtEditor.getContents();
});
You need isset function in if condition otherwise it will throw an error.你需要在 if 条件下使用 isset 函数,否则它会抛出错误。
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:无需为此编写任何 js 代码,只需将您的文本/内容放在 textarea 标签之间,就像:
<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.您只需要运行
instance.save()
方法。
const instance = SUNEDITOR.create();
instance.save()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.