22, August 2008

Block HTML from being entered in a form - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ 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

Author Topic: Block HTML from being entered in a form  (Read 587 times)
Supreme Overlord
***
Gender: Female
Posts: 148
1008 credits
Members referred : 0



« on: Aug 27, 2007, 08:58:17 PM »

How can I block HTML from being entered into my PHP guest book form?!
Nikolas' Servant Child
*
Posts: 30
184 credits
Members referred : 0


« Reply #1 on: Aug 27, 2007, 11: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: 6300
38626 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Aug 27, 2007, 11: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


Last blog : Create custom backups from your website using cURL
Supreme Overlord
***
Gender: Female
Posts: 148
1008 credits
Members referred : 0



« Reply #3 on: Aug 27, 2007, 11:35:58 PM »

Thanks Olaf!
Nikolas' Servant Child
*
Posts: 30
184 credits
Members referred : 0


« Reply #4 on: Aug 27, 2007, 11: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: 6300
38626 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Aug 28, 2007, 12:11:39 AM »

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


Last blog : Create custom backups from your website using cURL
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8020
41077 credits
Members referred : 3



« Reply #6 on: Aug 28, 2007, 10: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() Visit through proxy

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
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....

Topic sponsors:
Get a permanent link here for $1.99!


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?
Aug 22, 2008, 01:03:49 AM





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!


Forum Statistics
Total Posts: 36.084
Total Topics: 7.439
Total Members: 3.807
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: marthawelch

52 Guests, 3 Users online :

15 users online today:



Readers

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