Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts

    problem using striptags on textarea

    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.
    Last edited by durangod; 10-20-2012 at 05:53 PM.

  • #2
    New Coder
    Join Date
    May 2012
    Posts
    50
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Got any example code?

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    yep here ya go

    PHP Code:

    <?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

  • #4
    New Coder
    Join Date
    May 2012
    Posts
    50
    Thanks
    6
    Thanked 4 Times in 4 Posts
    PHP Code:
    $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/
    Last edited by bjarneo; 10-20-2012 at 05:00 PM.

  • #5
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    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...
    Last edited by durangod; 10-20-2012 at 05:24 PM.

  • #6
    New Coder
    Join Date
    May 2012
    Posts
    50
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by durangod View Post
    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 What screen resolution do you use?

  • #7
    New Coder
    Join Date
    May 2012
    Posts
    50
    Thanks
    6
    Thanked 4 Times in 4 Posts
    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 Code:
    <?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>[ICODE][ICODE][/ICODE][/ICODE]

  • #8
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    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.
    Last edited by durangod; 10-20-2012 at 05:54 PM.

  • #9
    New Coder
    Join Date
    May 2012
    Posts
    50
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by durangod View Post
    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

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •