How Can I Keep Html Code Out Of My Forms?
Thursday, June 25th, 2009 at
5:20 am
I’ve a mail form on my website and I’m wondering how I can validate what is put into the message part of my form so that I can keep html code out of it.
Can you help me with some code to strip out html code from my form?
Tagged with: Code. • Forms • HTML • Keep
Filed under: HTML
Like this post? Subscribe to my RSS feed and get loads more!
use javascript to exclude special characters like < and >. Check out the source. Ignore the message the guy wrote, the javascript you see should work. Just tweak it to your needs.
Use the jquery validation plug in, I use it on every form I code.
It spits out nice messages if people don’t fill out inputs properly.http://docs.jquery.com/Plugins/Validatio…
Add the latest jquery and the validation plugin in your header:
Then add the script to suit your specific form, for example:
It looks like you might be able to get ride of certain characters (code) using the removeAttrs( attributes ) option or addMethod to write your own function to make code characters invalid.
To strip HTML tags you can use the .replace() method and a regular expression. I suggest you find a good Reference book on Javascript and study the language a bit more before continuing. Without more detailed information on how/where you want this done, not many can help you.
Good Luck!
Sean Colicchio
Server Engineer
Host My Sitehttp://www.hostmysite.com/?utm_source=bb