[英]How to send value from suneditor textarea in php?
我想在 php Suneditor 中发送 textarea 值
PHP代码
if($_POST["submit"]){
$content = $_POST["txtEditor"];
echo $content;
}
html代码
<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]
],
})
编辑器完美运行。
我哪里做错了?
完整代码
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();
});
您必须将值从 suneditor 发送到 textarea,您可以这样做:
$(window).click(function() {
document.getElementById('txtEditor').value = txtEditor.getContents();
});
你需要在 if 条件下使用 isset 函数,否则它会抛出错误。
if(isset($_POST["submit"])){
$content = $_POST["txtEditor"];
echo $content;
}
无需为此编写任何 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');
您只需要运行instance.save()
方法。
const instance = SUNEDITOR.create();
instance.save()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.