Results 1 to 5 of 5

Thread: How to prevent people from posting HTML code in textarea

  1. #1
    Join Date
    Apr 2009
    Posts
    45
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Smile How to prevent people from posting HTML code in textarea

    Hello,
    I'd like to ask a question ..

    How do i prevent people posting HTML codes in an textarea ?

    thanks it really will helps me alot
    Last edited by egturnkey; 04-13-2009 at 05:56 PM. Reason: Problem has been resolved, thanks

  2. #2
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    You could use JavaScript like this:
    HTML Code:
    <textarea onkeyup="javascript:this.value=this.value.replace(/[<,>]/g,'');"></textarea>
    This won't work if JavaScript is turned off so you need to do server side checking as well.

    Good luck!
    Eddy Proca
    I love Dropbox. Get it through my girlfriend's referral link (I reached my limit) and both you and her get 500 MB extra! Thanks and you're welcome!

  3. The Following User Says Thank You to Snookerman For This Useful Post:

    egturnkey (04-13-2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    45
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    thanks very much , it now works perfect.

  5. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    As Snookerman said, it won't work if javascript is turned off. I suggest using PHP's htmlentities().
    Jeremy | jfein.net

  6. #5
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    You're welcome, glad to help!

    Good luck with your site!
    Eddy Proca
    I love Dropbox. Get it through my girlfriend's referral link (I reached my limit) and both you and her get 500 MB extra! Thanks and you're welcome!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •