I have been getting multiple support requests from developers how want to save the data edited in IPWEditor on the server side.
Saving information in the server side is a server-side feature and out of scope for IPWEditor (which is a client-side JQuery plug-in), moreover, it is programming language depended – a java developer might handle this differently from a .NET or a PHP developer.
Despite all that, I will try to give general guild on how it is done, I will be using PHP for the server-side examples but you can use any server side programming language you prefer.
Create a client side Ajax call
IPWEditor gives you the ability to run code once the user has saved his work on the wysiwyg editor, in my examples I have used the alert function to prompts the newly edited text:
$('.myipwe').editable( { type: 'wysiwyg', editor: oFCKeditor, onSubmit:function submitData(content){ alert(content.current) }, submit:'save' });
We will replace the alert(..) code with a jquery ajax call to the server:
$('.myipwe').editable( { type: 'wysiwyg', editor: oFCKeditor, onSubmit:function submitData(content){ $.ajax({ type: "POST",url: "save.php", data: {"content": content.current}, complete: function(){ }, //manage the complate if needed success: function(html){ }//get some data back to the screen if needed }); //close $.ajax( }, submit:'save' });
This will create a http Ajax call from the client side to save.php on the server side
Create the Server side save.php
So our next step is to create the server-side save.php:
<?php
header("Cache-Control: no-cache");
$content = $_POST["content"];
// TODO: implement saving $content in to a persistent database(AKA MySQL in php)
?>
I will spare you my version of how to connect PHP to a database you can read a good tutorial about it here.
That’s it!
You have now connected IPWEditor to a server side component and can now save the edited content.