...

View Full Version : Resolved problem using striptags on textarea



durangod
10-20-2012, 03:52 PM
Hi im just curious why when i use striptags on my textarea data then the whole textara dissappears.

But if i remove the striptags line the textarea displays fine.

Is there something about what striptags does that effects textarea's in specific in a bad way.

bjarneo
10-20-2012, 04:52 PM
Got any example code?

durangod
10-20-2012, 05:16 PM
yep here ya go




<?php

// sometimes this textarea is not blank but has a few spaces in there, so if it is less than 5 char then just trim it


//if i put stripgtags here the whole textarea vanishes off the page
//so i changed it to stripslashes instead and went without the striptags for now
//$rcur_comment = striptags($_SESSION['post']['txtComment']);

$rcur_comment = stripslashes($_SESSION['post']['txtComment']);

if (strlen($rcur_comment) < 5)
{
$rcur_comment = trim($rcur_comment);
}

if (strlen($rcur_comment) >= 120)
{
$rcur_comment = trim($rcur_comment);
}

$_SESSION['post']['txtComment'] = $rcur_comment;

?>


<td colspan="3" class="normal"><br />
120 Characters is less than 3 Lines of type. You can do it !!!<br />
*IMPORTANT! An attempt to bypass the 120 char min requirement by using duplicate characters will not be accepted.<br />

<textarea class="inputl" rows="10" name="txtComment" cols="59" tabindex="38" onKeyDown="textCounter(this.form.txtComment,this.form.remLentext);" onKeyUp="textCounter(this.form.txtComment,this.form.remLentext);"><?=$rcur_comment;?></textarea></td>






thanks

bjarneo
10-20-2012, 05:55 PM
$test['text'] = 'abcdefgh i aj sd ajkl dasnsad asl a';

$rcur_comment = strip_tags($test['text']);

if (strlen($rcur_comment) < 5)
{
$rcur_comment = trim($rcur_comment);
}

if (strlen($rcur_comment) >= 120)
{
$rcur_comment = trim($rcur_comment);
}
echo $rcur_comment;


Output: abcdefgh i aj sd ajkl dasnsad asl a


strip_tags should work just fine. striptags() is no php core function.. :) That's probably why it doesn't work.

Strip_tags example: http://workbench.no/blog/php-strip_tags/

durangod
10-20-2012, 06:22 PM
i know the php part of this is right, but did you test this on a textarea on your side?

also thanks for the link, but obviously the owner of that site does not look at code all day, if they did they would make the examples much bigger font. If you look at code all day, then having to look at that tiny text strains the eyes lol...

bjarneo
10-20-2012, 06:33 PM
i know the php part of this is right, but did you test this on a textarea on your side?

also thanks for the link, but obviously the owner of that site does not look at code all day, if they did they would make the examples much bigger font. If you look at code all day, then having to look at that tiny text strains the eyes lol...

Hmm, I'll test with a textarea.

Actually the owner of that site look at code all day :p What screen resolution do you use?

bjarneo
10-20-2012, 06:43 PM
Well it works as it should here.
Are you sure you are using the strip_tags ? and not striptags (except if this is a function you've created).



<?php

// sometimes this textarea is not blank but has a few spaces in there, so if it is less than 5 char then just trim it


//if i put stripgtags here the whole textarea vanishes off the page
//so i changed it to stripslashes instead and went without the striptags for now
$test['comment'] = 'hello oo o o o world';
$rcur_comment = strip_tags($test['comment']);

//$rcur_comment = stripslashes($test['comment']);

if (strlen($rcur_comment) < 5)
{
$rcur_comment = trim($rcur_comment);
}

if (strlen($rcur_comment) >= 120)
{
$rcur_comment = trim($rcur_comment);
}

$_SESSION['post']['txtComment'] = $rcur_comment;

?>


<td colspan="3" class="normal"><br />
120 Characters is less than 3 Lines of type. You can do it !!!<br />
*IMPORTANT! An attempt to bypass the 120 char min requirement by using duplicate characters will not be accepted.<br />

<textarea class="inputl" rows="10" name="txtComment" cols="59" tabindex="38" onKeyDown="textCounter(this.form.txtComment,this.form.remLentext);" onKeyUp="textCounter(this.form.txtComment,this.form.remLentext);"><?php echo $rcur_comment; ?></textarea></td>

durangod
10-20-2012, 06:51 PM
that was a typo on my end, i had strip_tags in my code, why i typed striptags in this example i dont know, tired i guess.

anyway nevermind ill close this out im tired and it will come to me im sure after i sleep thanks . Im tired, pissed off, and feel horrible.

Thanks anyway I dont even have the patience to look up what i put in there and what i didnt.

bjarneo
10-20-2012, 07:08 PM
that was a typo on my end, i had strip_tags in my code, why i typed striptags in this example i dont know, tired i guess.

anyway nevermind ill close this out im tired and it will come to me im sure after i sleep thanks . Im tired, pissed off, and feel horrible.

Thanks anyway I dont even have the patience to look up what i put in there and what i didnt.

Hehe, sleep makes debugging alot more easier :)

Fou-Lu
10-20-2012, 07:16 PM
Got short tags enabled or PHP 5.4 running? If not, <?= will not work.
Also, given your purpose above, I'd suggest not bothering your if checks for trim. Simply trim it off regardless. Otherwise I could enter 1 character, 118+ spaces, and 1 more character and its valid, so you just wasted an if check that will still give the same end result for my string. You'll need to check inside the string to validate it; using pattern matching is probably the easiest solution.

var_dump off the $rcur_comment before trying to show it in the textarea. That will tell you if you even have anything in that session to populate.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum