Use templates with CKEditor

Just like we did with TinyMCE, we will show the use of the WYSIWYG CKEditor online editor with templates and the automatic generation of a file name from the keywords contained in the article header.

The template is selected when the part is created and can be modified by editing an already saved part, selecting a file from the drop-down list. You can add your own templates to the catalog.

How does it work

The basic system consists of a series of scenarios. This is intended to be developed by the webmaster according to his needs .
In particular, you should create different templates .

Use template

  1. Extract the content from the archive and post it online on your site or test it locally in the Wamp, Xamp directory or equivalent.
  2. Launch install.php to create a login and password.
  3. It needs to be erased and returned to the Internet if you want to change your password .
  4. Download editor.php page
  5. Enter a title of one or more words.
  6. Select a template.
  7. Enter text and save.
  8. Add a link to an article on your site.

Display

For this very simple demonstration, we use only three files:

The main code is as follows

1) Enables the editor. Place this code in the HEAD section of the page:

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

2) Add a form displaying the submit button to save the text:

<form action="pagebuild.php" method="post" target="_top">
     <input type="hidden" name="page" value="demo-fr.php" >
     <input type="submit" value="Sauver le contenu">
</form>

6) Creating an editor instance. The code is inserted into the form, into the page body:

<textarea cols="80" id="editor1" name="editor1" rows="10">Vide</textarea>
<script type="text/javascript">
//<![CDATA[
var editor = CKEDITOR.replace( 'editor1' );
//]]>
</script>

When you click on the button, the pagebuild.php script will take the text you entered, which FCKeditor assigns to the variable, and is going to save it to a file.

The field in the hidden demo passes the URL of the editor page for the script to load.

The archive contains the CKEditor distribution, interface and PHP scripts, as well as sample templates.

Discussion board

Q. Use CKEditor

12-02-2009 12:11:12

nikolas83210

Hello, I learned about your site from friends, I have been looking for two weeks for a way to save what comes out of fkeditor in a text file, as you did, which would allow me to add to the page so that my client can change his web page himself. So, if you could give me the code for your brute.php file, which is registered in the txt file, please. warmly
12-02-2009 12:16:08

webmaster

Hi, here is the source code for the file (currently pagebrute.php):
<html>
<head>
<title>Document sans-titre</title>
<meta charset=utf-8>
</head>
<body>
<?php
if (isset( $_POST ))
   $postArray = &$_POST ;            // 4.1.0 or later
else
   $postArray = &$HTTP_POST_VARS ;    // prior to 4.1.0

$fname="fck/pagedemo.txt";
$nfile = fopen($fname, "w");
if($nfile != false)
{
    foreach ($postArray as $sForm => $value )
    {
        $yourText = $value ;
        fwrite($nfile, $yourText);
    }
    fclose($nfile);
}    

echo "You have written:<br/></br/>";
echo $yourText . "<br/></br>";
?>

<form action="demo-fck.php" method="post" target="_parent">
  <input type="submit" name="envoi" value="Revenir à l'éditeur">
</form></body>
</html>
For the French text, another file was created that did not affect the article. It will be updated so that you can download all the necessary files.
12-02-2009 17:19:18

nikolas83210

Thanks bcp for the response, it will be good. on the other hand, i have been trying for three days to find a solution for my pb, if you have an idea it will help me bcp bcp. I try to save some forms of fkeditor to bdd and nothing happens, it doesn't update in my bdd but there is no error message, this is what will be from my database, I created a news table with text field 1 in the textlong, in short, here's: I have two files: I have two files: formula aire.php

<? php include («FCKeditor/fceditor.php»);?> <html> <head> <title> Newscast </title> </head> <body> <form name = "editNews" method =" POST" action = "savedata.php"> <? php $ db = mysql_connect ('mabase', 'user', 'pass') or die ('Unable to connect'); if (! mysql _ select _ db ("mabase," $ db)) echo "Error: cannot select base <br>"; $ select = "SELECT text 1 FROM news"; $ req = mysql_query ($ select, $ db) or die ("Error:» .mysql _ error ()) while ($ row = mysql_fetch_array ($ req)) {echo '<tr>'; $ text = $ row [0];} $ oFCKeditor = new FCKeditor ("FCKeditor1"); $ oFCKeditor -> BasePath = 'FCK editor/' ;//Index to folder path FCKeditor $ oFCKeditor -> Width = "78%"; $ oFCKeditor -> Height = "50%"; $ oFCKeditor -> Value = $ text; $ $ o FCKeditor-> Create ();?> <br> <input type = "submit" value = "Submit"> </form> </body> </html> then savedata.php <? $ db = mysql_connect ('mabase', 'user', 'pass') or die ('Unable to log in'); if (! mysql _ select _ db ("mabase," $ db)) echo "Error: Unable to select base <br>"; $ updateNews = $ _ POST ["FCKeditor1"]; $ mysqlQuery = "UPDATE 'news" SET texte1 = "$ updateNews" "; mysql_query ($ mysqlQuery, $ db) или die ('MySQL error:' .mysql _ error ());?>

please, I have been on fceditor for three days now

12-02-2009 19:08:18

webmaster

For simplicity, I propose to first place the entire part of SQL in savedata, so replace the part of creating the pagebrute.php file with the equivalent of the SQL file. This would allow the file to be executed separately to ensure that this part of SQL works. Then I will check the interaction of this file with FCK Editor, which works in the demo version of the article...
13-02-2009 13:27:55

nikolas83210

1-я часть: $ updateNews = $ _ POST [«FCKeditor1»]; $ mysqlQuery = «UPDATE» news «SET text 1 =» $ updateNews «»; mysql_query ($ mysqlQuery, $ db) или die ('MySQL error:' .mysql _ error ()); 2-я часть: $ sql = «INSERT INTO NEWS VALUES (» $ FCKeditor1 «)»; mysql_query ($ sql) or die ("SQL error!" $ sql. '.mysql _ error ()); not being a developer and a starter, I added the second part taken from the forum, which makes it work, but I don't know why, because it doesn't make sense, both codes have the same purpose, except that the second part doesn't specify which field the value will be written in based on what I understood. maybe this string does not get a value: $ updateNews = $ _ POST ["FCKeditor1"]; Does that sound good to you?
13-02-2009 14:24:03

webmaster

The line $ updatedNews = $ _ POST ["FCKeditor1"] assumes that the variable FCKeditor1 passed as a parameter, which is the case when is the name of the form object. <input type = "text" name = "FCKeditor1" value =" "/> It might be, but I don't see it in the code. In the second part, $ FCKEditor1 is a PHP variable, which is not compatible with the first part.
14-02-2009 11:48:55

nikolas83210

$ mysqlQuery = «UPDATE 'news' SETTE1 = '$ FCKeditor1'»; mysql_query ($ mysqlQuery, $ db) или die ('MySQL error:' .mysql _ error ()); just by putting it, it works, it was the line $ updatedNews = $ _ POST ["FCKeditor1"], as you say, FCKeditor should not be recognized as a parameter, I am mistaken that I look in another fkeditor file, but this line works, after that I accept it everywhere I do not know
16-02-2009 16:36:14

nikolas83210

Well, you're right, and I have to decide pb, because I have to use the update function. So the problem after the research is that $ post doesn't get the information out of the form, and I don't know why, you, I do it in prayer iiiiiiiiiiiiiiiiqq something that will help me because here I am a little more please. then I have savedata.php: $ updateNews = $ _ POST ["FCKeditor1"]; $ mysqlQuery = "UPDATE" news "SET text 1 =" $ updateNews "; mysql_query ($ mysqlQuery, $ db) или die ('MySQL error:' .mysql _ error ()); mysql_close ();?> и в formula aire.php: <form name = «FCKeditor1» method =» POST» action = «savedata.php»> <? php//information for connecting to the enabled DB ('set.php'); echo "Error: unable to select base <br>"; $ select = 'SELECT text 1 FROM news'; $ req = mysql_query ($ select, $ db) or die ('Error:' .mysql _ error ()); while ($ row = mysql_fetch_array ($ req)) {echo '<tr>'; $ text = $ row [0];} $ oFCKeditor = new FCKeditor («FCKeditor1»); $ oFCKeditor -> BasePath = fkeditor/' ;/Путь от индекса к папке FCKeditor $ oFCKeditor -> Width = «78%»; $ oFCKeditor -> Height = «50%»; $ oFCKeditor -> Value = $ текст; $ oFCK editor-> Create ();?> <br> <input type = «submit» value = «Valder»> </form> </body> </html>
17-02-2009 00:51:43

nikolas83210

Finally, I found pb in my database, a field with comments was created, as well as in my table, but it was necessary to create a value in the same empty field, because we use the update function. In short, I'm a neophyte, but one day you have to start well. Anyway, thank you very much for your help.

Step failed, help

11-03-2007 13:21:30

Titof

Hello everyone and thanks for the help and explanation But I have to skip the step I can't save anything in my pagedemo.txt file And therefore there is nothing on my pagebuild.php page to put the code:
<?php

if (isset( $_POST ))
   $postArray = &$_POST ;			// 4.1.0 or later
else
   $postArray = &$HTTP_POST_VARS ;	// prior to 4.1.0

$fname="fck/pagedemo.txt";

$nfile = fopen($fname, "w");

if($nfile != false)
{
	foreach ($postArray as $sForm => $value )
	{
		fwrite($nfile, $value);
	}

	fclose($nfile);
}	

?>
It would be great if I could find help in advance thanks Titof
12-03-2007 14:54:51

webmaster

For clarification - a small summary. The edit page configures FCKEditor with the URL pagedemo.txt (which can be modified), as well as with the created object; She calls the PHP script pagebrute.php in French (pagebuild.php) in English. The pagebrute.php script saves the text in the pagedemo.txt file or another name selected and loads the edit page.
01-04-2007 19:20:31

mobilesong

Hello, I am trying to use CKeditor locally with easy php. the pagebuild.php script generates the pagedemo.txt file well, but.... This file is always empty. How to do it? Here are the various process steps I used after the tips on the "build cms" page. 1) I have placed in my folder your "php test" - pages "demo-editeur.php" and "pagebuild.php" - folder "CKeditor" containing the package CKeditor - an empty folder "fck" in which the file pagedemo.txt 2 is well generated) from the easy php interface I open a folder with the alias "test_php" - I press "demo-editeur.php" - I appeal well to the editor - I write my text - I send - the page "pagebuild.php" appears without my text inside - However, the file "pagedemo.txt" is well generated in the folder "fck" Please help Mobilesong
04-04-2007 16:33:09

user10

Does it work remotely by placing exactly the same set of files on the server?
14-04-2007 19:24:17

webmaster

This is done to work online.

CKeditor and bdd

24-05-2007 22:13:46

bubul

Hi! Thanks and bravo for the article on FCKeditor. One question remains unanswered: is it possible to connect the CKeditor to the SQL database? I'm trying to happen without success... I am attaching the end of the record update form code if you have an idea!:) Here (it's just a test...) the name modification is very effective, but not txt...
<form method="post" name="editor" action="<?php echo $editFormAction; ?>">
  <table align="center">
   
    <tr valign="baseline">
      <td nowrap align="right">Titre:</td>
      <td><input type="text" name="titre" value="<?php echo $row_Recordset2['titre']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Txt:</td>
      <td><input type="text" name="txt" value="<?php echo $row_Recordset2['txt']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"> </td>
      <td>
	  <?php
$oFCKeditor = new FCKeditor('editor') ;
$oFCKeditor->BasePath = '../fckeditor/';
$oFCKeditor->Value = $row_Recordset2[txt];
$oFCKeditor->Create() ;
$oFCKeditor->Name='txt';
?></td>
    </tr>
<input type="submit" value="Mettre à jour">
  </table>
  <input type="hidden" name="MM_update" value="editor">
  <input type="hidden" name="id" value="<?php echo $row_Recordset2['id']; ?>">
</form>
Thanks very much!!!
25-05-2007 14:39:31

webmaster

I haven't tried it personally, but everything can be done from PHP! I can't give a specific opinion when to me because the question is a bit vague. Should data taken from the database and returned to the database be edited? In this case, I will instead go through the intermediate text file used by PHP to change the base, otherwise I think it will introduce security flaws.