簡體   English   中英

如何從 php 中的 suneditor textarea 發送值?

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

如何從 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發送價值 從組合框發送值到textarea 如何將正文從.js頁發送到.php頁 如何從 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> 將文本區域的值傳遞給 PHP PHP-如何使用JavaScript AJAX發送textarea值並將其輸出為.txt文件以供瀏覽器下載? 將html作為值發送到textarea 在textarea中發送值 如何將網頁從文本區域發送到iframe 如何從文本區域獲取價值
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM