3

I want to validate the data entered in tinymce editor in server side in PHP. I need to allow standard html tags but need to avoid scripts and style tags attached to html elements. Please help me.

3

2 Answers 2

0

use DOMDocument to load the html generated with tinymce and search for your restricted html with DOMXPath

0

Have a look at the javascript strip_tags function mentioned here: TinyMCE Paste As Plain Text

You need to apply this before you send the code to the server.

4
  • Just like your server side should be validating your regular input controls that could be accepting text that is attempting a SQL injection, you need to validate on the server that text seemingly from TinyMCE doesn't have malicious scripts. You can't trust client-side code as it's trivial to bypass validations and special characters and tags won't get automatically escaped or stripped by TinyMCE.
    – csrowell
    Commented Nov 1, 2023 at 18:51
  • that is correct - server side measures sdould be in place too, but strip_tags is one way to make it more difficult
    – Thariama
    Commented Nov 3, 2023 at 8:22
  • Won’t strip_tags get rid of the standard html tags the OP wants to keep?
    – csrowell
    Commented Nov 3, 2023 at 13:35
  • 1
    not necessarily, the second paramter of strip_tags allows to insert allowed tags that do not get tripped
    – Thariama
    Commented Nov 6, 2023 at 15:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.