我有一个带有输入和文本区域(ckeditor)的表单,在用ajax提交表单后,所有输入字段的值都被发送到数据库表,但ckeditor textarea除外,我不知道为什么!

我在这里用同样的问题try 了一些解决方案,但没有脉络!

HTML PART

<form id="submitForm">
... some inputs ...

<textarea class="form-control" name="details" rows="6" id="product-details"></textarea>

<button class="btn btn-solid btn-rounded" id='publish' type="submit"> SAVE </button>

</form>

JS PART

$(document).ready(function() {
                       
    ClassicEditor.create( document.querySelector("#product-details"), {
        toolbar: {
            items: [
                "heading", "|",
                "alignment", "|",
                "bold", "italic", "strikethrough", "underline", "subscript", "superscript", "|",
                "link", "|",
                "bulletedList", "numberedList", "todoList",
                "-", // break point
                "fontfamily", "fontsize", "fontColor", "fontBackgroundColor", "|",
                "code", "codeBlock", "|",
                "insertTable", "|",
                "outdent", "indent", "|",
                "uploadImage", "blockQuote", "|",
                "undo", "redo"
            ],
            shouldNotGroupWhenFull: false
        }
    });

$("#submitForm").on('submit', function(e) {
        e.preventDefault();
        
        $.ajax({
            type: 'POST',
            url: 'ajax/create-product.php',
            data: new FormData(this),
            dataType: 'json',
            contentType: false,
            cache: false,
            processData: false,
            beforeSend: function() {
                $("#publish").prop("disabled", true);
            },
            success: function(response) {                
                if (response.status == '1') {
                    Command: toastr["success"](response.message, "")
                    window.location.href = response.url;
                
                } else {
                    $("#publish").prop("disabled", false);
                    Command: toastr["error"](response.message, "")
                }
            }
        });
    });   
});

推荐答案

它不起作用,因为编辑器的值没有直接expose 到下面的文本区域.我认为这有一些 Select ,但这也会起作用:在提交到隐藏控件时复制值.

var instance;

$(document).ready(function() {

  ClassicEditor.create(document.querySelector("#product-details")).then(editor => instance = editor);

  $("#submitForm").on('submit', function(e) {
    e.preventDefault();

    document.querySelector("[name=details").value = instance.getData();

    $.ajax({
      type: 'POST',
      url: 'ajax/create-product.php',
      data: new FormData(this),
      dataType: 'json',
      contentType: false,
      cache: false,
      processData: false,
      beforeSend: function() {
        $("#publish").prop("disabled", true);
      },
      success: function(response) {
        if (response.status == '1') {
          Command: toastr["success"](response.message, "")
          window.location.href = response.url;

        }
        else {
          $("#publish").prop("disabled", false);
          Command: toastr["error"](response.message, "")
        }
      }
    });
  });
});
textarea {
  width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/34.2.0/classic/ckeditor.js"></script>

<form id="submitForm">
  <textarea class="form-control" name="details-editor" rows="6" id="product-details"></textarea>

  <p>this textarea should be hidden:</p>
  <textarea name="details"></textarea>

  <button class="btn btn-solid btn-rounded" id='publish' type="submit"> SAVE </button>

</form>

Php相关问答推荐

在AJX请求中使用简写后,FormData出现非法调用错误

产品ACF值在WooCommerce我的账户订单的附加列中为空

在WooCommerce中执行一次银行电汇确认付款代码

输入手写CSV时在PHP中进行日期判断

尽管包含目标日期,但日期范围比较仍有意外输出

如何在WordPress中为特定自定义帖子类型自定义URL struct

在php中有没有办法比较两个包含相同枚举类型的枚举数组

从WooCommerce购物车和 checkout 页面自定义发货标签

Htaccess-重写对&api.php";的API请求以及对";web.php";的其他请求

MySQLi是否在事务错误时删除保存点(并且仅删除保存点)?

在Laravel中为表添加前缀,以将它们逻辑地分组

如何在php网站代码中清理浏览器缓存

将WooCommerce WC_Order对象与wp_Schedule_Event一起使用

如何从WooCommerce checkout 帐单邮箱字段中删除星号?

如何将WooCommerce产品从一个产品复制到另一个产品S

WooCommerce - 调用功能ID不正确.不应直接访问订单属性

如何使用在产品快速编辑菜单前端的自定义框中 Select 的值更新 woocommerce 产品属性值?

如何用 php ML 解决这个问题?

PHP 日期格式:ISO8601 与 ISO8601_EXPANDED

使用 PHP ImageMagick 库将 pdf 文件的前 n 页转换为单个 png 图像文件