1

私はここ数時間、ckeditor(textarea)に入力されたデータ(text / html)をPHPファイルに単純に投稿しようとしてきました。

彼らのAPIは、データがフォーム送信時にデータを自動的に投稿すると主張していますが、そうではなく、何も返しません。

編集:ここに実際のコードがあります:

    <?php
    require("fns.php");
    // grab tab content from database
    $tab = array();
    $query ="SELECT * FROM tabs";
    $db_conn = db_connect();
    $results = mysql_query($query,$db_conn);
    while($row = mysql_fetch_array($results))
    {
    $tab[]= $row;
    }

// form validation
if($_POST['btnSave'])
{
    // grab selected tab ID
    $tabId = $_POST['tabId'];
    $title = $_POST['txtTitle'];
    $content = $_POST['ckeditor'];


    // all fields required
    if(isset($tabId) && isset($title) && isset($content))
    {   
        // update recorde where id = tabId
        $query = "UPDATE tabs SET title = '$title', content = '$content' WHERE id = $tabId";
        if($content !== "")
        {
            if(mysql_query($query,$db_conn))
            {
                $message = "<h3 style='color:#003300;'>Changes Saved!</h3><br /><p>".$content."</p>";
                header("Location:testtabs.php");
            }
        }
        else
        {
            $message ="<h3 style='color: #950000;'>Content cannot be blank!</h3>";
        }
    }
}

?>

    <!-- in head section -->
      <script type="text/javascript">  
    $(document).ready(function() {
    // inflate ckeditor
    $('#ckeditor').ckeditor();
    //track selected tab
    var currentId = -1; 
        // Tab initialization
        var $tabs = $('#tabs').tabs({
         select: function(event, ui){
        /*
        ui.index: zero based index selected tab 
        ui.tab: anchor element of the selected tab
        ui.panel: element containing the content for the selected tab
        */

        // get current tab ID for php script
        var currentId = ui.index + 1;
        $("#tabId").val(currentId);
        var tabName = $(ui.tab).text();
        var content = $(ui.panel).html();
        // swap title
        $( '#title' ).val( tabName );
        // swap content
        $("#ckeditor").val(content);
    }   
});

});

    <body>
    <?php  echo $message; ?>
<div id="tabs">
    <ul>
        <li><a href="#tabs-1"><?php echo $tab[0]['title'];?></a></li>
        <li><a href="#tabs-2"><?php echo $tab[1]['title'];?></a></li>
        <li><a href="#tabs-3"><?php echo $tab[2]['title'];?></a></li>
    </ul>
    <div id="tabs-1">
        <div class="content"> 
               <?php echo $tab[0]['content'];  ?>
        </div>
    </div>
    <div id="tabs-2">
        <div class="content"> 
               <?php echo $tab[1]['content'];  ?>
        </div>
    </div>
    <div id="tabs-3">
        <div class="content"> 
               <?php echo $tab[2]['content'];  ?>
        </div>
    </div>
</div>

<?php 
    if (isset($_SESSION['valid_user']) && ($_SESSION['account_type'] == 'ADMIN')) 
    {
        // display editor with tab 1 content
        ?>
        <table id="tab-editor">
            <form action = 'testtabs.php' method ='post'>
            <input type="hidden" id="tabId" name ="tabId" value="-1"/>
                <tr><td>Title: <input type='text' name='txtTitle' id='title' value='<?php echo $tab[0]['title'];?>'/></td></tr>
                <tr><td>Tab Content:</td></tr><tr><td> <textarea name='ckeditor' id='ckeditor' class='tab-editor'><?php //echo $tab[0]['content'];?></textarea></td></tr>
                <tr><td><input type='submit' name='btnSave' value='Save Changes' /></td>
            </form>
        </table>
        <?php
    }
    ?>

4

2 に答える 2

0

CKEditorは、テキストエリアのコンテンツを使用してエディターにデータを入力することにより、テキストエリアから(おそらく他の要素からでも)CKEditorのインスタンスを作成します。とにかくjQueryを使用する場合:

$('#ckeditor').val("Initial text (test)");

textareaタグ内にテキストを配置しています。CKEditorインスタンスを作成したら、CKEditorメソッドを使用してデータを取得する必要があります:http: //docs.cksource.com/ckeditor_api/

具体的には、次のものが必要になると思います。

http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#getData

PS:私の悪い英語でごめんなさい

編集:編集を見ていませんでした、ごめんなさい

于 2012-10-26T21:30:57.280 に答える
0

従来のckeditorjavascriptに戻り、正常に動作するようになりました...

    CKEDITOR.replace( 'ckeditor' );
    // Tab initialization
// Tab initialization
var $tabs = $('#tabs').tabs({
    select: function(event, ui){
        /*
        ui.index: zero based index selected tab 
        ui.tab: anchor element of the selected tab
        ui.panel: element containing the content for the selected tab
        */

        // get current tab ID for php script
        var currentId = ui.index + 1;
        $("#tabId").val(currentId);
        var tabName = $(ui.tab).text();
        var content = $(ui.panel).html();
        // swap title
        $( '#title' ).val( tabName );
        // swap content
        CKEDITOR.instances['ckeditor'].setData(content);

    }   
});
于 2012-10-31T18:58:56.043 に答える