0

Good morning dudes,

I have a little issue, I have a rich text editor but on copy and pasting it retains a lot of the gunk, unwanted fonts classes. It is even worse when copy and pasting from microsoft word. Here are some of the things I want:

  • To remove all unwanted formatting except bold tags, uls, lis, hyperlinks and p tags
  • On paste either, control +v or right click paste, remove formatting (cross platform solution that works on all browsers
  • Is it best to use javascript and PHP for validation? So should I do a double pass and use a PHP function to clean the input?
  • When I save to the database I have limited the content field to 500 chars, but if the user copy and pastes too much text it will drop a closing html tag and thus mess up my form.
3
Contributors
7
Replies
40
Views
3 Years
Discussion Span
Last Post by diafol
0

Why don't you check how an editor like TinyMCE does it?

Removing formatting can be a pain, it could be HTML, XML or RTF.

0

I ended up using

http://patisserie.keensoftware.com/en/pages/remove-word-formatting-from-rich-text-editor-with-javascript

Which looks very good.

To detect copy and paste I am using:

http://www.mkyong.com/jquery/how-to-detect-copy-paste-and-cut-behavior-with-jquery/

And finally, I'm using PHP dom document to strip id and classes.

http://stackoverflow.com/questions/3026096/remove-all-attributes-from-an-html-tag

I just need a way to hook this all in to my rich text fields so I don't repeat the code.

Thanks for the help.

0

I'm assuming that this is a javascript issue? You wouldn't use php to clean pasted input before you passed it "from the editor to the server" would you?

Anyway, sanitizing tags is impt in php to ensure no script tags etc are included. Whitelisting tags may be a way of doing it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.