Adding Pages Online with a Wysiwyg Editor

Our CMS needs for an editor to enter the content of the pages and put them into the website.
We are using FCKeditor for the example, but you can use a different editor, wysiwyg or not, as well. This one is under the LGPL licence, it is easy to install and is perfectly convenient for us.

For this very simple demo, we are using only three files:
- editor-demo.php. This page.
- pagebuild.php. A PHP script that stores the text you enter into a file.
- pagedemo.txt. The file that will be created.

If you use another editor, you have to replace the two parts of PHP code below, but the form and the pagebuild.php file should remain unchanged.

The current demo page holds some PHP code that loads FCKeditor (the code comes from the documentation of the editor):

1) Including the editor. Put this code on the first line of the page:

<?php 
	include("FCKeditor/fckeditor.php") ;
?>
2) Creating an instance. The code is inserted into the body of the page, into the form:
<?php
$oFCKeditor = new FCKeditor('FCKeditor1') ;
$oFCKeditor->BasePath = 'FCKeditor/';
$oFCKeditor->Value = 'Empty.' ;
$oFCKeditor->Create() ;
?> 

3) And adding a form that displays a send button that will run the PHP script.

<form action="pagebuild.php" method="post" target="_blank">
     <input type="submit" value="Send">
</form>

When you click on the button, the pagebuild.php script will get the text you have typed, that is assigned to a variable by FCKeditor, and will store it into a file .
You can then load the newly created file by typing its URL or at a click on the link provided in the demo...

Demonstration

In an article to come, we will insert the text you have typed into a template to create a real HTML page.

More informations

Question or problem? Check the new forum, perhaps you question is answered, otherwise feel free to register and post your comments.

(c) 2007 Denis Sureau and Sandrine Takis. Scriptol.com
Licence: You are free to use the code of this tutorial to motorize your own site. Please do not put the tutors and other files on another website, add a link to the article instead. But you can print the pages and distribute them along with the code for educational purpose.