Topic: Block HTML from being entered in a form (Read 1621 times)
World Wide Whale
Gender:
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 < and >, for example.
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 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.
thats not true, check the function strip_tags
World Wide Whale
Gender:
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:
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
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3