Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: text area help

  1. #1
    Join Date
    Mar 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default text area help

    i'm creating a guest book and i use a text area with multiple text. My problem is, when someone press "enter" for many times, the display of my guest book view is totally ruin. So my question is how to validate my textarea so no "enter" allowed, or just few "enter" press allowed. If someone know, please help me.
    Thanks

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default Submit Once

    There are probably better ways to do this using server side scripting but, if that is unavailable to you (check first with the folks providing your guestbook), this script should help minimize the problem. If you restrict access to your guestbook to folks using JavaScript, it will all but eliminate the problem.
    Submit Once! Form validation
    Enjoy!

  3. #3
    Join Date
    Mar 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    But this script is for pressing submit button over and over, still it can't validate pressing "enter" many times.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Sorry, my mistake, I assumed that enter was but one way to press the submit button, like it is on the demo for this script. Something should be able to be worked out to adapt this script to your needs. To do so we need to see what you've got.
    PLEASE: Include the URL to your problematic webpage that you want help with.
    How about:
    Disable "Enter" Key in Form script?
    Last edited by jscheuer1; 03-28-2005 at 07:24 AM.

  5. #5
    Join Date
    Mar 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Its ok, but i haven't upload my webpage yet, i wanna make sure i'v validate everything before i upload it
    This is what happen when someone press enter so many times in your guest book
    ex :
    http://www.gbiontherock.com/bukuTamuLihat.asp

    All i wanna know is, is there any ways to limit the pressing of the "enter" button to in example 5 times max, or something like that?
    Thanks
    Last edited by selece28; 03-28-2005 at 08:25 AM.

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by selece28
    All i wanna know is, is there any ways to limit the pressing of the "enter" button to in example 5 times max, or something like that?
    In other words, you want to count the number of "lines" in a submission, correct? In principle, you could use a regular expression to analyse the string content:

    Code:
    var array = textareaObj.value.match(/.*(\r|\n|\r\n)|$/g);
    The resulting array would contain matches for the expression - basically the content of each line, including empty lines, but not the last line (it will be returned empty). Irrespective of that last detail, the number of lines would be indicated by the length property of the returned array.

    If your guest book really does break when large, multiline entries are added, might I suggest you find a better guest book?

    Mike

  7. #7
    Join Date
    Mar 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I create my guest book myself using only textarea and display it using html script and php script. what do u mean find a better guest book? Do u have any suggestion where to find one?
    Thanks

  8. #8
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by selece28
    what do u mean find a better guest book?
    If having several lines in a post breaks your layout, then the system is broken. I'm afraid there isn't any other way of putting that.

    Yes, you could place some limits on content, but that should be to stop someone doing something malicious like posting 500 lines of random text, or posting one long string of text that makes horizontal scrolling necessary. However, it shouldn't be to prevent your layout from falling apart.

    Do u have any suggestion where to find one?
    You're guaranteed to find plenty of them about the Web. Google is your friend. Bravenet is also a good place to start.

    Mike

  9. #9
    Join Date
    Mar 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok i'v overcome my layout problems, now what if someone doing malicious things like posting 500 lines of random text, or posting one long string of text that makes horizontal scrolling necessary.
    Is there any code to limit the lines?
    I've put a limit to my textarea to 500char
    Thanks

  10. #10
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by selece28
    [...] what if someone doing malicious things like posting 500 lines of random text, or posting one long string of text that makes horizontal scrolling necessary.
    Is there any code to limit the lines?
    Lines should always be delimited by carriage return, line feed pairs. You can use the substr_count function to count the number of times these pairs occur:

    PHP Code:
    $lines substr_count($text"\r\n") + 1
    You can use the wordwrap function to limit line lengths. If there are word breaks already present, the function will use them but if not it will force a break.

    PHP Code:
    $wrappedText wordwrap($text80"<br>\n"1); 
    You should only need to take this step when displaying entries. Use the number of lines and the total entry length to determine whether to reject a post.

    Read the PHP manual for more information about these functions. They're both listed under String functions.

    I've put a limit to my textarea to 500char
    If you haven't done so already, make sure you check that server-side.

    Mike

Bookmarks

Posting Permissions

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