Concepts
Save button
Calling the save
method would make HTTP requests from JS to saveURL
and your server has to handle the request. It is up to you to handle the requests on server side and store the data.
Save options
There are up to 5 parameters that can be customized for the save action: saveParam
,saveURL
, saveParams
, saveRequestType
and editable.saveError
.
• saveParam tells the editor in which parameter of the request to put the edited content. By default it is set into the body
param.
• saveURL is the most important option, it is the URL where the save request is made.
• saveRequestType specifies the HTTP request type for the save action.
• saveParams option can be used to pass additional parameters in the request.
• editable.saveError event is invoked if any error occurs during the upload process.
Initialize the WYSIWYG HTML editor and save button
<div id="myEditor"></div> <button id="saveButton">Save</button> <script> $(function() { $('#myEditor') .editable({ // Set the save param. saveParam: 'content', // Set the save URL. saveURL: 'http://example.com/save', // HTTP request type. saveRequestType: 'POST', // Additional save params. saveParams: {id: 'my_editor'} }) .on('editable.saveError', function (e, editor, error) { // Do something here. }) }); $('#saveButton').click (function () { $('#myEditor').editable('save') }) </script>
Receive request on the server
When the save button is hit, the editor will make a HTTP request to your server. The content will be sent in the content
parameter of the request and the server has to process the request and save the data in the DB. If any additional saveParams
are passed they will also be included in the request.
PHP example: For the code above you would get the rich text editor's content in $_POST['content']
variable and the additional information in $_POST['id']
.