![](/img/trans.png)
[英]How can get values from select-inputs with the same name using php method POST?
[英]How can I get the values from CKEDITOR using POST in PHP?
我在 HTML 中獲取 CKEDITOR 的值時遇到了麻煩。 在CKEDITOR中輸入一些HTML標簽並提交后。 POST 響應沒有輸出。 這是我的代碼。 我不知道它是否有些復雜,因為我還使用了 jquery-validation 插件。
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
你能幫我解決這個問題嗎?
試試這個:
<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
?>
感謝您的幫助,我設法通過下載這個小插件http://ckeditor.com/addon/save來解決它
我在我的 js 部分添加了配置。
config.extraPlugins = 'save';
現在我可以獲得 CKEDITOR 值。
你能試試這個方法嗎
$details = htmlentities($_POST['editor']);
試試這個,它工作正常
$("form[name='blog_form']").on("submit", function (e) {
e.preventDefault();
var editor_data = CKEDITOR.instances.editor.getData(); // editor is the textarea field's name
$("form[name='blog_form'] textarea[name='editor']").val(editor_data);
var data = new FormData(this);
您將獲得表單的所有字段及其值,並在 google 控制台中與網絡確認。 像:
b_title: This is just a testing Title of the blog.
b_heading: This is the Heading of the Blog.
b_date: 2019-09-06
b_time: 17:00
b_excerpt: test
editor: <p>testing <strong>may be fine </strong>now with the <span
style="color:#1abc9c"><span style="font-size:24px">TextEditor</span></span></p>
b_file: (binary)
b_tags: tags
我們現在在上面的編輯器鍵中獲取我們的 texteditor 值。
在 PHP 頁面上,您可以獲得如下值:
$blog = new Blog($db);
$blog->b_title = $_POST['b_title'];
$blog->b_heading = $_POST['b_heading'];
$blog->b_content = $_POST['editor']; // ... and so on
Mayank 的答案是正確的,但我使用“for in”語法為此做了一個最靈活的方法,您可以在發送數據之前在 submitHandler 上進行以下操作:
submitHandler: function(form) {
//Update textarea elements before send...
for (let input in CKEDITOR.instances) {
CKEDITOR.instances[input].updateElement();
}
form.submit(); //send data
}
你在 $_POST 上得到了正確的數據
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.