簡體   English   中英

使用 Tinymce 文本編輯器首次發送時內容文本區域為空

[英]Content text area empty on first send using Tinymce text editor

我以前從未遇到過這種情況,這就是為什么我來看看是否有人可以解釋為什么或導致這種情況的原因。

基本上我使用以下 html javascript 在 Tinymce 編輯器中調用:

<script type="text/javascript">
    jQuery(document).ready(function() {
        tinymce.init({
            selector: "#content",
            theme: "modern",
            plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu paste imagetools Customlayouts Customshortcodes, autoresize responsivefilemanager"
            ],
            toolbar: "Customlayouts Customshortcodes | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist | link responsivefilemanager image media | code fullscreen",
            image_advtab: true ,
            relative_urls: false,
            external_filemanager_path:"http://<?php echo $_SERVER['HTTP_HOST']; ?>/Libs/filemanager/",
            filemanager_title:"Responsive Filemanager" ,
            external_plugins: { "filemanager" : "/Libs/filemanager/plugin.min.js"}
        });
    });
</script>       
<div class="form-group">
    <label for="content" class="col-sm-2 control-label">Page Content</label>

    <div class="col-sm-9">
        <textarea id="content" name="content"></textarea>
    </div>
</div> 

所以問題是,在您第一次提交表單時,它不會發送任何可以在這里看到的內容:

'type' => string 'sendform' (length=8)
  'name' => string '' (length=0)
  'title' => string '' (length=0)
  'slug' => string '' (length=0)
  'tags' => string '' (length=0)
  'description' => string '' (length=0)
  'content' => string '' (length=0)
  'islive' => string 'false' (length=5)

但是,如果我沒有做任何事情而再次單擊提交按鈕,則會發送如下所示的內容:

  'type' => string 'sendform' (length=8)
  'name' => string '' (length=0)
  'title' => string '' (length=0)
  'slug' => string '' (length=0)
  'tags' => string '' (length=0)
  'description' => string '' (length=0)
  'content' => string '<p>sdfsdfsdf</p>' (length=16)
  'islive' => string 'false' (length=5)

我正在使用 ajax 發送最有可能是問題的表單。 這是我的 jquery 提交:

jQuery(document).ready(function($){
    $('#addnewpage').on('submit', function(e){

        e.preventDefault();

        $.ajax({
            url: "/Applications/Controllers/Pages/ajax-pages.php",
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
            success: function(data){

                if(data === 'success'){ 

                    window.location.href = "/Control-Panel/Pages/Manage/?success=added";

                } else {

                    $('#ubl-fail').slideUp(300);
                    $('#ubl-fail').html(data);
                    $('#ubl-fail').delay(350).slideDown(300);
                    window.scrollTo(0, 0);

                }

            }           
        });

    });
});

我不明白為什么會發生這種情況我正在檢查我的控制台日志以查看是否出現任何錯誤,但沒有。 我在 html 或 php 方面也沒有錯誤。 特別是考慮到目前在 php 方面,我只是這樣做:

var_dump($_POST);

無論如何,這就是問題所在,如果有人能解釋為什么會發生這種情況,我將非常感激。

謝謝

我遇到過同樣的問題。 原來我所要做的就是在提交之前添加 tinyMCE.triggerSave() 。

$('#addnewpage').on('submit', function(
    tinyMCE.triggerSave();
    $('form#document-form').submit();
});

添加這個腳本...

<script type="text/javascript" src="tinymce/tinymce.min.js"></script>
<script type="text/javascript">
    tinymce.init({mode : "specific_textareas", editor_selector : "myTextEditor",    theme: "modern",    theme_advanced_fonts : "Andale Mono=andale mono,times; "+                "Arial=arial,helvetica,sans-serif; "+                "Arial Black=arial black,avant garde; "+                "Book Antiqua=book antiqua,palatino; "+                "Comic Sans MS=comic sans ms,sans-serif; "+                "Courier New=courier new,courier; "+                "Georgia=georgia,palatino; "+                "Helvetica=helvetica; "+                "Impact=impact,chicago; "+                "Symbol=symbol; "+                "Tahoma=tahoma,arial,helvetica,sans-serif; "+                "Terminal=terminal,monaco; "+                "Times New Roman=times new roman,times; "+                "Trebuchet MS=trebuchet ms,geneva; "+                "Verdana=verdana,geneva; "+                "Webdings=webdings; "+                "Wingdings=wingdings,zapf dingbats",    plugins: [        "advlist autolink lists link image charmap print preview hr anchor pagebreak",        "searchreplace wordcount visualblocks visualchars code fullscreen",        "insertdatetime media nonbreaking save table contextmenu directionality",        "emoticons template paste textcolor colorpicker textpattern"    ],    toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",    toolbar2: "fontselect |  forecolor backcolor emoticons",    image_advtab: true,    templates: [        {title: 'Test template 1', content: 'Test 1'},        {title: 'Test template 2', content: 'Test 2'}    ]});
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM