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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    137
    Thanks
    1
    Thanked 0 Times in 0 Posts

    validating textarea using php

    hi

    i need to validate textarea of a html form using php

    <textarea name="comments" cols="26" rows="3" id="comments"><?php echo($comments);?></textarea>

    presently my php code to validate the text area is

    if($comments == "" )
    {
    $error.="<br>Please enter your comments";
    }

    with this code if a user hits the space bar once or couple of times as a matter of fact there are no characters entered by the user i do not want this to happen, if a user simply hits the spacebar and does not type anything i should be able to display an alert message.

    please advice how i can change the above php code.

    thanks.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Try using this instead:

    PHP Code:
    if ( strlen trim $comments ) ) == 

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I really hope you are taking the proper security measures with your php. From what you posted it looks like you are using register_globals which is a security risk. And if you are putting this stuff into a database and aren't escaping anything then you are open to sql injection.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Location
    Grahamstown, South Africa
    Posts
    237
    Thanks
    6
    Thanked 17 Times in 17 Posts
    Relax, aero meister. I didnt see any mysql there. ;-)

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by idalatob View Post
    Relax, aero meister. I didnt see any mysql there. ;-)
    I know that, and thats why I said "if".
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Regular Coder
    Join Date
    Apr 2008
    Location
    New Jersey
    Posts
    116
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Could also suggest:

    PHP Code:
    if(!preg_match('/\S/'$comments)) 
    Chaos
    Lost Souls: text based RPG | MUDseek: MUD gaming search | MUDfind: MUD resource sites | Discordian Quotes


  •  

    Posting Permissions

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