2017-05-26 88 views
1

我之前從未遇到過這個問題,這就是爲什麼我來看看是否有人能夠闡明爲什麼或者是什麼導致了這種情況。使用Tinymce文本編輯器首先發送的內容文本區域爲空

基本上我用下面的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); 

反正就是這個問題,我將非常感激,如果任何人都可以闡明爲什麼發生這種情況的一些情況。

謝謝

+0

我有同樣的問題。你有沒有找到解決方案? – elMeroMero

+0

@elMeroMero不,我從來沒有解決過這個問題,我不得不使用正常的形式發送它,而最終沒有發送ajax,至少有點讓人討厭。 – Robert

回答

1

我有同樣的問題。事實證明,我所要做的就是在提交之前添加tinyMCE.triggerSave()。

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

完美,謝謝! –

相關問題