简体   繁体   English

如何从 php 中的 suneditor textarea 发送值?

[英]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()

如何从 html 获取和发送值<textarea>&lt;i&gt;to a PHP page?&lt;/div&gt;&lt;/i&gt;&lt;b&gt;到 PHP 页面?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我创建了一个用于图像上传的表单。 此表单还包括一个标签,用于添加有关正在上传的图像的信息。 每当单击“上传”按钮时,我都需要将标签中的文本发送到页面“savetofile.php”。</p><p> 目前图片上传正常,图片信息发送正确,但我无法从“savetofile.php”页面的标签中获取文本。</p><p> 形式</p><pre>&lt;form action="savetofile.php" enctype="multipart/form-data" id="form1" method="post"&gt; &lt;div&gt; &lt;label for="fileToUpload"&gt;Take or select photo(s)&lt;/label&gt;&lt;br/&gt; &lt;input accept="image/*" capture id="fileToUpload" name="fileToUpload" onchange="fileSelected();" type="file"/&gt; &lt;/div&gt; &lt;div&gt; &lt;br&gt;&lt;br&gt; &lt;label for="notes"&gt;Notes:&lt;/label&gt; &lt;textarea cols="50" id="notes" maxlength="2000" name="notes" placeholder="Please enter any additional information here" rows="4" onchange="this.form.submit()"&gt;&lt;/textarea&gt; &lt;br&gt;&lt;br&gt; &lt;/div&gt; &lt;div id="details"&gt;&lt;/div&gt; &lt;div&gt; &lt;input onclick="uploadFile()" type="button" value="Upload"/&gt; &lt;/div&gt; &lt;div id="progress"&gt;&lt;/div&gt; &lt;/form&gt;</pre><p> 保存到文件.php</p><pre> $text = $_POST['notes']; _log('text: '.$text);</pre><p> 上传文件()</p><pre> function uploadFile() { var fd = new FormData(); var count = document.getElementById('fileToUpload').files.length; for (var index = 0; index &lt; count; index++) { var file = document.getElementById('fileToUpload').files[index]; fd.append('myFile', file); } var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.addEventListener("load", uploadComplete, false); xhr.addEventListener("error", uploadFailed, false); xhr.addEventListener("abort", uploadCanceled, false); xhr.open("POST", "savetofile.php"); xhr.send(fd); }</pre><p> 当前 output:</p><pre> Undefined index: notes... text:</pre></div> - How to get and send values from html <textarea> to a PHP page?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从textarea发送价值 - send value from textarea 从组合框发送值到textarea - send value from combobox to textarea 如何将正文从.js页发送到.php页 - how to send a body from a textarea from a .js page to a .php page 如何从 html 获取和发送值<textarea>&lt;i&gt;to a PHP page?&lt;/div&gt;&lt;/i&gt;&lt;b&gt;到 PHP 页面?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我创建了一个用于图像上传的表单。 此表单还包括一个标签,用于添加有关正在上传的图像的信息。 每当单击“上传”按钮时,我都需要将标签中的文本发送到页面“savetofile.php”。</p><p> 目前图片上传正常,图片信息发送正确,但我无法从“savetofile.php”页面的标签中获取文本。</p><p> 形式</p><pre>&lt;form action="savetofile.php" enctype="multipart/form-data" id="form1" method="post"&gt; &lt;div&gt; &lt;label for="fileToUpload"&gt;Take or select photo(s)&lt;/label&gt;&lt;br/&gt; &lt;input accept="image/*" capture id="fileToUpload" name="fileToUpload" onchange="fileSelected();" type="file"/&gt; &lt;/div&gt; &lt;div&gt; &lt;br&gt;&lt;br&gt; &lt;label for="notes"&gt;Notes:&lt;/label&gt; &lt;textarea cols="50" id="notes" maxlength="2000" name="notes" placeholder="Please enter any additional information here" rows="4" onchange="this.form.submit()"&gt;&lt;/textarea&gt; &lt;br&gt;&lt;br&gt; &lt;/div&gt; &lt;div id="details"&gt;&lt;/div&gt; &lt;div&gt; &lt;input onclick="uploadFile()" type="button" value="Upload"/&gt; &lt;/div&gt; &lt;div id="progress"&gt;&lt;/div&gt; &lt;/form&gt;</pre><p> 保存到文件.php</p><pre> $text = $_POST['notes']; _log('text: '.$text);</pre><p> 上传文件()</p><pre> function uploadFile() { var fd = new FormData(); var count = document.getElementById('fileToUpload').files.length; for (var index = 0; index &lt; count; index++) { var file = document.getElementById('fileToUpload').files[index]; fd.append('myFile', file); } var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.addEventListener("load", uploadComplete, false); xhr.addEventListener("error", uploadFailed, false); xhr.addEventListener("abort", uploadCanceled, false); xhr.open("POST", "savetofile.php"); xhr.send(fd); }</pre><p> 当前 output:</p><pre> Undefined index: notes... text:</pre></div> - How to get and send values from html <textarea> to a PHP page? 将文本区域的值传递给 PHP - Pass the value from a textarea to PHP PHP-如何使用JavaScript AJAX发送textarea值并将其输出为.txt文件以供浏览器下载? - PHP - How to send textarea value with JavaScript AJAX and output it as .txt file for browser to download? 将html作为值发送到textarea - Send html as value to textarea 在textarea中发送值 - Send value in textarea 如何将网页从文本区域发送到iframe - How to send a web page from a textarea to iframe 如何从文本区域获取价值 - How to get the value from the textarea
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM