Yahoo! Developer Network Home - Help

YUI Library Examples: Rich Text Editor (beta): Editor Data Post with Connection Manager

Rich Text Editor (beta): Editor Data Post with Connection Manager

This example demonstrates how to use Connection Manager to post data to the server, filter it and return it to the Editor.



Setting up the Editors HTML

Setting up the Editor's HTML is done by creating a textarea control on the page.

Setting up the Editors Javascript

Once the textarea is on the page, then initialize the Editor like this:

Setup the Connection Manager Object

We need to setup the callback object for Connection Manager. In the handleSuccess function, we will eval the data returned from the server.

Then we will call myEditor.setEditorHTML with the new HTML.

Setup the Button and the Checkbox

Using a Button control, we create the new Button and subscribe to the click event to begin the transaction.

Before making the request, we need to pull the HTML from the editor by calling the myEditor.saveHTML method. This will place the filtered HTML from the Editor back into the textarea.

Once we have that, we contruct our query string, and fire off the request.

Note: The request is wrapped in a short setTimeout to allow the browser to finish the cleanup calls that the Editor is making.

Snippet of server side PHP

On the server side, first we filter the HTML to remove harmful HTML elements. Then we are doing a simple text filter (in this case the Elmer Fudd filter) and adding a "tagline" to the bottom of the data.

Once our filtering is complete, we are returning the new data to the browser.

Full Example Javascript Source

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings