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?How can I keep html code out of my forms?
use javascript to exclude special characters like %26lt; and %26gt;. Check out the source. Ignore the message the guy wrote, the javascript you see should work. Just tweak it to your needs.How can I keep html code out of my forms?
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:
%26lt;script type=';text/javascript'; src=';http://ajax.googleapis.com/ajax/lib?br>
%26lt;script type=';text/javascript'; src=';jquery.validate.min.js';%26gt;%26lt;/script%26gt;
Then add the script to suit your specific form, for example:
%26lt;script id=';demo'; type=';text/javascript';%26gt;
$(document).ready(function() {
$(';#yourFormID';).validate({
rules: {
Name: ';required';,
Company: ';required';,
Title: ';required';,
Phone: ';required';,
Email: {
required: true,
email: true
},
Comments: ';required';
},
messages: {
Name: ';Please enter your name';,
Company: ';Please enter your company';,
Title: ';Please enter your title';,
Phone: ';Please enter your phone number';,
Email: ';Please enter a valid email address';,
Comments: ';Please enter your comments';
}
});
});
%26lt;/script%26gt;
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 Site
http://www.hostmysite.com/?utm_source=bb
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment