Topic: Block HTML from being entered in a form (Read 587 times)
Supreme Overlord
Gender:
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 < and >, for example.
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6300
38626 credits Members referred : 374
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 < and >, for example.
Supreme Overlord
Gender:
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:
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