为什么我的动态CMS表单不会每次都加载?

时间:2021-10-28 13:16:33

I'm using CKEditor to created the portion of my CMS for the user to input content. My CMS is a bar/menu at the top with the sections of the site for the user to create, update, or delete an entry.

我正在使用CKEditor创建CMS的一部分,供用户输入内容。我的CMS是顶部的栏/菜单,其中包含用户创建,更新或删除条目的站点部分。

When the user selects an option I send the request for the form items to php using jquery AJAX $.post. The function returns the code and I use $('#loadCMS').html(data) to create the form without reloading the page. This work great and debugging always shows the correct code returned.

当用户选择一个选项时,我使用jquery AJAX $ .post将表单项的请求发送到php。该函数返回代码,我使用$('#loadCMS')。html(data)创建表单而不重新加载页面。这项工作很棒,调试总是显示返回的正确代码。

However, CKEditor only loads the first time an item is selected. It may load again but it's rare.

但是,CKEditor仅在第一次选择项目时加载。它可能会再次加载但很少见。

CKEditor is javascript that sits in the head and replaces specified textareas with the editor

CKEditor是javascript,位于头部并用编辑器替换指定的textareas

<head>
...
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
...
</head

what is loaded dynamically to call the editor

动态加载什么来调用编辑器

<textarea name="editor1"></textarea>
    <script type="text/javascript">
        CKEDITOR.replace( "editor1",
        {
            toolbar :
            [
            ['Source'],
            ['Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker'],
        ['Undo','Redo','-','RemoveFormat'],
        ['Bold','Italic','Underline'],
        ['Subscript','Superscript'],
        ['NumberedList','BulletedList'],
        ['Link','Unlink'],
        ['Image','Flash','HorizontalRule','SpecialChar','Format'],
        ['Maximize', 'ShowBlocks','-','About']
            ],
            width : '1000',
            height : '300',
            filebrowserBrowseUrl : '/ckfinder/ckfinder.html',
            filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?Type=Images',
            filebrowserFlashBrowseUrl : '/ckfinder/ckfinder.html?Type=Flash'
        });
    </script>

jquery

jQuery的

$('#portfolioCreate').click(function()
    {
        var detailsList = new Array('title','medium','original');
        $.post('cms.php',{detailsList: detailsList,images:"imageOn",subimgNum:0,content1:"Comments"},
        function(data)
        {
            $('#loadCMS').html(data);
            $('#debug').val(data);
        });
    });

The forms are created dynamically every time. However, the textareas replaced by CKEditor does not always replace, it's just blank not even the textarea box shows. The first time a selection is made it works. If the user chooses to create a new blog entry the text area is replaced, if they then choose to update bio no text area is ever replaced even if they go back to create a new blog entry.

表单每次都是动态创建的。但是,由CKEditor替换的textareas并不总是替换,它只是空白,甚至textarea框都没有显示。第一次选择它是有效的。如果用户选择创建新的博客条目,则替换文本区域,如果他们然后选择更新生物,则即使他们返回创建新的博客条目,也不会替换文本区域。

-----------------SOLUTION-------------------------

- - - - - - - - -解 - - - - - - - - - - - - -

dynamic php

动态的PHP

$key = md5(time().rand())
<textarea name="'.$key.'"></textarea>
<script type="text/javascript">
CKEDITOR.replace("'.$key'",
{
     .....
});
<input type="hidden" value="'.$key.'" name="content1Key" />
</script>

php to pull from form

php从表单中拉出来

$content1Key = $_POST['content1Key'];
$content1 = $_Post[$content1Key];

1 个解决方案

#1


1  

CKEditor is very picky about dynamically creating forms because of the way they store references (in one global array keyed by textarea name I believe). Try to give each textbox a unique name to avoid it trying to return an existing reference that's been destroyed/overwritten, and after loading each new form you need to call CKEDITOR.replace.

CKEditor非常挑剔动态创建表单,因为它们存储引用的方式(在一个由textarea名称键入的全局数组中我相信)。尝试为每个文本框指定一个唯一的名称,以避免它尝试返回已被销毁/覆盖的现有引用,并在加载每个新表单后需要调用CKEDITOR.replace。

#1


1  

CKEditor is very picky about dynamically creating forms because of the way they store references (in one global array keyed by textarea name I believe). Try to give each textbox a unique name to avoid it trying to return an existing reference that's been destroyed/overwritten, and after loading each new form you need to call CKEDITOR.replace.

CKEditor非常挑剔动态创建表单,因为它们存储引用的方式(在一个由textarea名称键入的全局数组中我相信)。尝试为每个文本框指定一个唯一的名称,以避免它尝试返回已被销毁/覆盖的现有引用,并在加载每个新表单后需要调用CKEDITOR.replace。