[英]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.