Javascript to not allowing any html in textarea?

Discussion in 'JavaScript' started by tnt7, Aug 25, 2007.

  1. #1
    I am pretty new to this have been searching the web for hours for a solution. I have viewed many validation tactics, but can't seem to find exactly what I am looking for.

    I would like to write a scipt to prohibit any html from being in a textarea field what so ever in our form.

    We are getting a lot of spam right now. Below is our form. Thanks for any help you can give or a point in the right direction.
    
    <form method=post action="/process.php" method="post" name="form" target="_blank" "><input type="hidden" name="id" value="product-id">How do you rate this item?&nbsp;<select name="rating"><option value="" selected="selected">-</option><option value="5" >5 stars</option><option value="4" >4 stars</option><option value="3" >3 stars</option><option value="2" >2 stars</option><option value="1" >1 stars</option></select><br>Your Name:<br><input name="reviewname" type="text" size="35"><br>Your Location (City, State)<br><input name="location" type="text" size="35"><br>Type your review in the space below:<br><textarea name="text" rows="5" cols="40" rows="5"></textarea><br><input type="submit" value="submit"><input type="hidden" name=".autodone" value="product-id" /></form>
    
    Code (markup):
     
    tnt7, Aug 25, 2007 IP
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    This protection must be done in process.php with strip_tags or similar function in php.

    A bot is like a browser without JS activated, so any JS protection is useless.
     
    gibex, Aug 25, 2007 IP
  3. ssanders82

    ssanders82 Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you want to allow users to add html but prevent robots from posting at all, add a captcha.
     
    ssanders82, Aug 27, 2007 IP
  4. garazy

    garazy Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You should definetly do server side validation on any input entered regardless of what client side validation you have.

    However, if you want to prevent HTML being entered into a textarea I recommend having a look at TMT Validator (search it at google i can't link to it). It has options to prevent HTML input as well as a load of other validators.
     
    garazy, Aug 31, 2007 IP
  5. Awanish

    Awanish Peon

    Messages:
    53
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes TMT Validator helps to prevent the HTML Input, that should help.
     
    Awanish, Sep 4, 2007 IP