【问题标题】:Get html output from tinymce with laravel使用 laravel 从 tinymce 获取 html 输出
【发布时间】:2022-06-10 19:50:07
【问题描述】:

我正在尝试在我的 cms 中实现 tinymce 5。我正在使用 Laravel 8。

    <div class="mt-5">
      <label for="crud-form-2" class="form-label">Description</label>
      <textarea id="editor"  name="innerText"></textarea>
   </div>


tinymce.init({
            selector: '#editor',
            plugins: [
                "advlist", "anchor", "autolink", "charmap", "code", "fullscreen",
                "help", "image", "insertdatetime", "link", "lists", "media",
                "preview", "searchreplace", "table", "visualblocks",
            ],
            toolbar: "undo redo | styles | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
        });

假设我在 tinymce 编辑器上构建了一些 html 结构。

<h3>Some description</h2>

但是当我发布所有表单数据时,我无法访问 html 结构。我只得到 'Some Description' 如何从 tinymce 获取 html 输出。

【问题讨论】:

    标签: laravel tinymce tinymce-5


    【解决方案1】:

    你能试试这个,看看你是否得到了想要的输出

    // Get the HTML contents of the currently active editor
    tinyMCE.activeEditor.getContent();
    
    // Get the raw contents of the currently active editor
    tinyMCE.activeEditor.getContent({format : 'raw'});
    
    // Get content of a specific editor:
    tinyMCE.get('content id').getContent()
    
    the activeEditor is current editor,but i use tinyMCE.get('editor1').getContent() can not get the value of my editor, hope it can help you
    

    Tinymce API:http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.getContent

    【讨论】:

    • 嘿。我在 textarea 值处正确获取 html 输出。但是如果我将这些值发布到我的 laravel 控制器,我只会显示文本,而不是 html 输出。我没有在我的控制器中使用 strip_tags 等。只是简单的请求,$request->innerText.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-15
    • 2015-07-15
    • 2010-10-06
    • 1970-01-01
    相关资源
    最近更新 更多