Forum Moderators: open

Message Too Old, No Replies

Disable html on <textarea>

disabe html on <textarea>

         

Sephh

6:41 pm on May 18, 2006 (gmt 0)

10+ Year Member



Here is the example:
<form name="contact" method="post" action="prelucrate.php" enctype="multipart/form-data"><textarea....

I want to know how can I disable the html when someone writes in it. The user can add there some scripts to autoredirect to other websites.
Also that way I could remove <br> when I want to start a new line.

jshanman

7:07 pm on May 18, 2006 (gmt 0)

10+ Year Member



I want to know how can I disable the html when someone writes in it. The user can add there some scripts to autoredirect to other websites.

disable what html?

The textarea?

<textarea onchange="this.disabled = true"></textarea>

But that doesn't make sense...

- JS

Sephh

7:12 pm on May 18, 2006 (gmt 0)

10+ Year Member




Like in phpbb there is a option: disable html code, that users couldn`t add links or images on the board.

jshanman

7:41 pm on May 18, 2006 (gmt 0)

10+ Year Member



I use a server side code(php) to accomplish this, but it does allow certian tags(b,i,u,etc).

If you want just a regular expression:
textarea.value.replace(\<.+>\ig,"");

this will kill all text between a < and a >, so if a user is typeing programming code, they would need to use &lt; and &gt;

- JS

Sephh

9:30 pm on May 18, 2006 (gmt 0)

10+ Year Member



I use php too.

jshanman

2:07 pm on May 19, 2006 (gmt 0)

10+ Year Member



OT: PHP code. I got this from the comments on php.net under strip_tags.

function removeEvilAttributes($tagSource){
$stripAttrib = "' (class夸avascript:她nclick她ndblclick她nmousedown她nmouseup她nmouseover她nmousemove她nmouseout她nkeypress她nkeydown她nkeyup她ncontextmenu)=\"(.*?)\"'i";
$tagSource = stripslashes($tagSource);
$tagSource = preg_replace($stripAttrib, '', $tagSource);
return $tagSource;
}

function removeEvilTags($source) {
$allowedTags = '<h1><h2><h3><h4><h5><h6><br><b><p><u><i><a><ol><ul><li><pre><hr><blockquote><table><tr><td><th><span><div><strong><tbody><sup><font>';
$source = strip_tags($source, $allowedTags);
return preg_replace('/<(.*?)>/ie', "'<'.removeEvilAttributes('\\1').'>'", $source);
}

$goodText = removeEvilTag($evilTextAreaText);

- JS