I read the Doc's and I didn't find the answer. I guess if you're using fckeditor in just an email form you'd be alright, as it's all outgoing. But I'm using fckeditor in a form that is putting the information into a mysql database. Going into the database it works fine, but if you want to be able to edit what you put into the database with fckeditor you're in trouble.
I'm using the javascript version inside my php form. I can do a View Source and see that the information was pulled from the database, but it will not display.
I didn't see anything in the Doc's that deals with using fckeditor to edit database information, that was entered in with fckeditor. If it were to display the information, I don't know if it would be in a WYSIWYG format or HTML. If it would only display the information in HTML (showing all the tags) you might as well just use a textarea.
I would like to use fckeditor in both an add_ibfo.php script and an edit_info.php script or is it impossible to use fckeditor an edit script?
You may need to read more about working with databases. First of all be sure that magic_quotes is off, or if it is enabled, remove slashes before working with $_REQUEST/$_POST/$_GET/$_FILES data. Then, before saving data to DB, use one of dedicated functions to escape strings, like mysql_real_escape_string - only such function will prevent you against SQL injection. Please note that even the example at php.net (below description of get_magic_quotes_gpc) is generally wrong: instead of adding slashes if magic_quotes is off, it's better to strip slashes if it's on.
Job Ad:
string(777) "
National Company looking for an Optician to work/manage a small Optical Shoppe.
Requirements:
* Neat in Appearance..
* Licensed or 5 years experience.
* Able to work M-F 9:00 AM - 5:00 PM.
* Salary: Starting pay will be $60K a year with a possible increase after 6 mos.
Benefits:
* Medical and Vision.
* 2 weeks paid vacation per year after the first year, 1 week the first year.
* Sick days.
* 1 free pair of glasses per year.
Apply: Fax resume to 555-555-1234 or email a .txt version to here@there.com.
"
The above showed on the Web page, but without the fckeditor toolbar and editing box. But at least something showed up, so we're getting closer to the desire effect. Ultimately, I want to be able to display what was entered into the database the first time (in the WYSIWYG format), so that it can be edited and the updated information put back into the database.
I have been able to do this successfully. Feel free to PM me if you continue to have problems in getting this to display your content correctly for you to edit it, as I would be glad to help you out and point out the issues you may be having with your PHP code and setting Values and the such like (took me a bit to figure it out to begin with as well as the examples deal with just 'displaying' your text to HTML and not storing into a database first).
herschwolf wrote:I have been able to do this successfully. Feel free to PM me if you continue to have problems in getting this to display your content correctly for you to edit it, as I would be glad to help you out and point out the issues you may be having with your PHP code and setting Values and the such like (took me a bit to figure it out to begin with as well as the examples deal with just 'displaying' your text to HTML and not storing into a database first).
-Nathan
Please, instead of PM, post everything in public because other people might find that information useful. If you had trouble to understand the samples then maybe you can suggest other samples, instructions or whatever, but do it here or in the wiki so everybody can benefit from that information
The only problem with the sample is it doesn't provide a "storage" sample, or content that would upload to a database. This doesn't mean the sample HAS to do this to show what it can do. The PHP examples given only output the text and you have it run through a htmlspecialchars() function that needs to be removed if you are going to store it in the database - otherwise you store the converted HTML instead of the actual HTML.
For storage into a database the PHP htmlspecialchars() function step is NOT needed. Below is the function that I created to display my editor box and display the MySQL content to the box. This function only takes data provided to it so just simply calling it will provide you with errors. Pull your content from your database and then call the function when you extract the data from your database.
function editorBox($id,$message) {
//create new instance of the editor
$oFCKeditor = new FCKeditor($id) ;
//set the base directory for the editor
$oFCKeditor->BasePath = 'editor/';
$oFCKeditor->Config["ToolbarStartExpanded"] = false;
$oFCKeditor->ToolbarSet = "Expanded";
//this is where I pull in the actual text to display
$oFCKeditor->Value = $message;
//create the actual text box with editor window
$oFCKeditor->Create() ;
}
The config settings that I use are:
BasePath: set to the folder I have the FCKeditor stored in and must be relative to file that function is called from NOT the file that the function is stored in (ie. from index.php if the function is called here NOT _scripts/functions.php where the function below is placed.)
Config["ToolbarStartExpanded"]: set to either true or false depending on if you wanted the toolbar fully expanded when created. The function I used this for was for multiple boxes and having them all expanded was confusing so I just closed them all to begin with.
ToolbarSet: I created a new ToolbarSet in the fckconfig.js file that removed some functions that I didn't need my client to use and weren't needed for the project. Make sure the call here is an actual defined ToolbarSet or you will get an error.
Value: This is where the content that will display in the box upon creation is placed. The $message variable is what is set outside of this function. When called using a $editor = editorBox(1,$content) <- the $content variable is the message I want to display. The function then sets this (as $message) to the Value parameter and creates the editor with this content already displayed in the box.
The $id and the $message variable requirements were so I could have multiple boxes displayed without having to paste the same code multiple times. It made it much easier to increase a number through PHP and have the code loop through my content and create my editor boxes. The $id is what the name="" attribute of my textarea became since I had multiple boxes and wanted a quick way to identify which box went with which data.
Play around with it to see if it's what you need or not.
Re: PHP & mysql integration
value
Wiktor Walc
CTO, CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+
Re: PHP & mysql integration
I used this:
this:
and this:
but it will not display the information.
I'm using the javascript version inside my php form. I can do a View Source and see that the information was pulled from the database, but it will not display.
I didn't see anything in the Doc's that deals with using fckeditor to edit database information, that was entered in with fckeditor. If it were to display the information, I don't know if it would be in a WYSIWYG format or HTML. If it would only display the information in HTML (showing all the tags) you might as well just use a textarea.
I would like to use fckeditor in both an add_ibfo.php script and an edit_info.php script or is it impossible to use fckeditor an edit script?
Re: PHP & mysql integration
Then, before saving data to DB, use one of dedicated functions to escape strings, like mysql_real_escape_string - only such function will prevent you against SQL injection.
Please note that even the example at php.net (below description of get_magic_quotes_gpc) is generally wrong: instead of adding slashes if magic_quotes is off, it's better to strip slashes if it's on.
Now regarding this code:
this one is correct, but under one condition, that if you do:
just before doing this assignment, you will see exactly that string you want to edit (without slashes).
So generally the problem is that your string is wrongly escaped.
Wiktor Walc
CTO, CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+
Re: PHP & mysql integration
When I pull from the database to display the information I use this:
I don't know how to implement your suggestion:
Like this?
<strong>Job Ad:</strong><br> <?php var_dump($content); die(); ?> <script type="text/javascript"> var oFCKeditor = new FCKeditor('content'); oFCKeditor.BasePath = "./../fckeditor/"; oFCKeditor.ToolbarSet = 'MyToolbar' ; oFCKeditor.Height = 400 ; oFCKeditor.Value = "<?php echo addslashes($content); ?>"; oFCKeditor.Create(); </script>Re: PHP & mysql integration
<strong>Job Ad:</strong><br> <?php var_dump($content); die(); ?> <script type="text/javascript"> var oFCKeditor = new FCKeditor('content'); oFCKeditor.BasePath = "./../fckeditor/"; oFCKeditor.ToolbarSet = 'MyToolbar' ; oFCKeditor.Height = 400 ; oFCKeditor.Value = "<?php echo addslashes($content); ?>"; oFCKeditor.Create(); </script>And got this on the front side:
The above showed on the Web page, but without the fckeditor toolbar and editing box. But at least something showed up, so we're getting closer to the desire effect. Ultimately, I want to be able to display what was entered into the database the first time (in the WYSIWYG format), so that it can be edited and the updated information put back into the database.
Re: PHP & mysql integration
Wiktor Walc
CTO, CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+
Re: PHP & mysql integration
Re: PHP & mysql integration
-Nathan
Re: PHP & mysql integration
Please, instead of PM, post everything in public because other people might find that information useful. If you had trouble to understand the samples then maybe you can suggest other samples, instructions or whatever, but do it here or in the wiki so everybody can benefit from that information
Re: PHP & mysql integration
For storage into a database the PHP htmlspecialchars() function step is NOT needed. Below is the function that I created to display my editor box and display the MySQL content to the box. This function only takes data provided to it so just simply calling it will provide you with errors. Pull your content from your database and then call the function when you extract the data from your database.
function editorBox($id,$message) { //create new instance of the editor $oFCKeditor = new FCKeditor($id) ; //set the base directory for the editor $oFCKeditor->BasePath = 'editor/'; $oFCKeditor->Config["ToolbarStartExpanded"] = false; $oFCKeditor->ToolbarSet = "Expanded"; //this is where I pull in the actual text to display $oFCKeditor->Value = $message; //create the actual text box with editor window $oFCKeditor->Create() ; }The config settings that I use are:
BasePath: set to the folder I have the FCKeditor stored in and must be relative to file that function is called from NOT the file that the function is stored in (ie. from index.php if the function is called here NOT _scripts/functions.php where the function below is placed.)
Config["ToolbarStartExpanded"]: set to either true or false depending on if you wanted the toolbar fully expanded when created. The function I used this for was for multiple boxes and having them all expanded was confusing so I just closed them all to begin with.
ToolbarSet: I created a new ToolbarSet in the fckconfig.js file that removed some functions that I didn't need my client to use and weren't needed for the project. Make sure the call here is an actual defined ToolbarSet or you will get an error.
Value: This is where the content that will display in the box upon creation is placed. The $message variable is what is set outside of this function. When called using a $editor = editorBox(1,$content) <- the $content variable is the message I want to display. The function then sets this (as $message) to the Value parameter and creates the editor with this content already displayed in the box.
The $id and the $message variable requirements were so I could have multiple boxes displayed without having to paste the same code multiple times. It made it much easier to increase a number through PHP and have the code loop through my content and create my editor boxes. The $id is what the name="" attribute of my textarea became since I had multiple boxes and wanted a quick way to identify which box went with which data.
Play around with it to see if it's what you need or not.
Re: PHP & mysql integration