28, May 2012

Block HTML from being entered in a form - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Block HTML from being entered in a form
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: Block HTML from being entered in a form  (Read 1621 times)
World Wide Whale
***
Gender: Female
Posts: 154
1052 credits
Members referred : 0



« on: Aug 27, 2007, 07:58:17 pm »

How can I block HTML from being entered into my PHP guest book form?!
Cyberpunk Wannabe
*
Posts: 34
208 credits
Members referred : 0


« Reply #1 on: Aug 27, 2007, 10:19:01 pm »

You can't. However, you can encode it to ensure that it is not transmitted back to the browser as raw HTML by using the htmlentities function. If you do that, then it will show up as-typed because <> are converted to &lt; and &gt;, for example.
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Aug 27, 2007, 10:31:17 pm »

You can't. However, you can encode it to ensure that it is not transmitted back to the browser as raw HTML by using the htmlentities function. If you do that, then it will show up as-typed because <> are converted to &lt; and &gt;, for example.

thats not true, check the function strip_tags

World Wide Whale
***
Gender: Female
Posts: 154
1052 credits
Members referred : 0



« Reply #3 on: Aug 27, 2007, 10:35:58 pm »

Thanks Olaf!
Cyberpunk Wannabe
*
Posts: 34
208 credits
Members referred : 0


« Reply #4 on: Aug 27, 2007, 10:39:48 pm »

strip_tags doesn't stop people entering the tags in the form, it just strips them. Yes, that's an alternative to quoting them. You could also do something else to them with a regex. My point was: you have to deal with the fact that someone might enter them in the form, rather than trying to prevent it at source.

Personally, I dislike strip_tags, since it discards the input --- what if someone wanted to enter text that just happened to look like HTML tags?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Aug 27, 2007, 11:11:39 pm »

sure preventing people to enter html tags is not possible, but if someone like to block html in his guestbook "strip_tags" is the answer Wink

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #6 on: Aug 28, 2007, 09:16:44 am »

Personally, I dislike strip_tags, since it discards the input --- what if someone wanted to enter text that just happened to look like HTML tags?

In that case you can use htmlspecialchars()

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7046
Tags : PHP Form No HTML Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Block HTML from being entered in a form
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 09:11:15 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.