2016-08-22 19 views
1

我在獲取HTML中CKEDITOR的值時遇到了麻煩。 在CKEDITOR中輸入一些HTML標籤並提交之後。 POST響應沒有輸出。這是我的代碼。我不知道是否因爲我還使用了jquery-validation插件而導致一些併發症。如何在PHP中使用POST從CKEDITOR獲取值?

HTML

<?php echo form_open('users/user/sendEmail', array('id' => 'send-mail-form', 'role' => 'form')); ?> 
<div class="row row_field"> 
    <div class="col-md-12"> 
     <label for="editor">Email Body:</label> 
     <textarea name="email_body" id="editor"></textarea> 
    </div> 
</div> 

JS

$('#editor').ckeditor(); 

jquery的驗證

$('#send-mail-form').validate({ 
    rules: { 
     email_subject: { 
      required: true, 
      minlength: 15 
     }, 
     email_body: { 
      required: true, 
      minlength: 50 
     } 
    }, 
    messages: { 
     email_subject: { 
      required: "The Email Subject is required", 
      minlength: "The email subject shoud be 15 characters and above." 
     }, 
     email_body: { 
      required: "Email body is required", 
      minlength: "The email body should be 5o characters and above." 
     } 
    }, 
    submitHandler: function(form) { 
     form.submit(); //send data 
    } 
}); 

PHP服務器端

public function sendEmail() { 

     fp($this->input->post()); //no output 

     fp(htmlentities($this->input->post('email_body'))); //no output also 

你能幫我嗎?

回答

4

試試這個:

<script> 
    var data = CKEDITOR.instances.editor1.getData(); 

    // Your code to save "data", usually through Ajax. 
</script> 

或者

<?php 
    $editor_data = $_POST[ 'editor1' ]; // where editor1 is the name of html element 
?> 

Reference Guide

+0

所以我需要通過AJAX來做到這一點? :好生病嘗試 – Jerielle

0

ü可以試試這個方法

$details = htmlentities($_POST['editor']); 
+0

好生病嘗試。 – Jerielle

+1

由於'editor'是textarea的ID,$ _POST ['editor']'不會存在 - POST使用名稱 – RamRaider

+0

ooh yes。抱歉的錯誤,需要使用「email_body」 –

1

感謝您的幫助球員,我 MANAG e通過下載這個小插件來解決它 http://ckeditor.com/addon/save

然後我在我的js部分添加配置。

config.extraPlugins = 'save'; 

現在我可以得到CKEDITOR值。

+0

嗨,先生,你能檢查我的文章嗎? https://stackoverflow.com/questions/47206753/how-to-et-the-value-in-the-ckeditor-codeigniter – Angel

相關問題