View Full Version : text area help
03-28-2005, 02:05 AM
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.
03-28-2005, 03:19 AM
Submit Once! Form validation (http://www.dynamicdrive.com/dynamicindex11/submitonce.htm)
03-28-2005, 04:34 AM
But this script is for pressing submit button over and over, still it can't validate pressing "enter" many times.
03-28-2005, 04:43 AM
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.
Disable "Enter" Key in Form script (http://www.dynamicdrive.com/dynamicindex16/disableenter.htm)?
03-28-2005, 07:20 AM
Its ok, but i haven't upload my webpage yet, i wanna make sure i'v validate everything before i upload it :D
This is what happen when someone press enter so many times in your guest book
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?
03-28-2005, 01:28 PM
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:
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? :)
03-29-2005, 01:47 AM
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?
03-29-2005, 02:30 PM
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.
03-30-2005, 05:27 AM
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
03-30-2005, 03:00 PM
[...] 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:
$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.
$wrappedText = wordwrap($text, 80, "<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 500charIf you haven't done so already, make sure you check that server-side.
03-31-2005, 04:49 AM
WOww Thank you very much, you helped me a lot
I'll try it now
Arigatou Gozaimasu :D
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.