I need some help!
I have a textfield (multiline), and everything works fine when you are using it and typing in, the lines break. But actually when you submit all the text, then the text shows up as one line, no breaks no nothing! If I specify width, it still doesn't work. I'm not a big expert on perl or cgi to know how to break the lines apart, but somebody please help!!!
I need to have the MESSAGE, which is the textinput, to brake lines whenever it reaches that width. I think this is the perl line that needs to have something changed:
This piece comes before the other one I posted, maybe this one can help better:
sub check_input {
my($username,$usermail,$userurl,$usermessage);
$username = $FORM{'username'};
$usermail = $FORM{'country'};
$userurl = $FORM{'url'};
$FORM{'message'} =~ s/\cM\n/<br>\n/g;
$usermessage = $FORM{'message'};
if ($username !~ /\S/) {
if ($required{'username'} eq "yes") {
&error('You forgot to fill in the <u>Name</u> field. Please correct it and re-submit!');
}
$FORM{'username'} = "anonymous";
}
if ($usermail !~ /\S/) {
if ($required{'country'} eq "yes") {
&error('You forgot to fill in the <u>country</u> field. Please correct it and re-submit!');
}
$FORM{'country'} = "";
}
if ($userurl !~ /^http:\/\/[._a-z0-9-]+\.[._a-z0-9-]+/i) {
if ($required{'url'} eq "yes") {
&error('The <u>URL</u> seems not to be valid. Please correct it and re-submit!');
}
$FORM{'url'} = "";
}
if ($usermessage !~ /\S/) {
if ($required{'message'} eq "yes") {
&error('You forgot to fill in the <u>Message</u> field. Please correct it and re-submit!');
}
$FORM{'message'} = "No Comments";
Let me first try to understand/restate the problem.
You are submitting a textfield to a script and you want to somehow insert line breaks.
You probably already understand that, when typing into a textfield, it will automatically line wrap, so there are no returns. So what you see in CGI is what was entered.
My problem is understanding why you want to enter the line breaks in the CGI script. Maybe the reason will point to a solution.
I think nedals has asked the key questions, but just to try to anticipate - if you want the block of text divided into a fixed number of characters per line, that is easy, just looop through taking x characters from the beginning of the field until you have no more. More likely you want to break between words in which case the logic is something like
(to break into lines no more than x chars long)
while text left
start at character x
work backwards until you get to the beginning orfind the first space
if you are back at the beginning just take the first x chars (you will have to break it as they have entered a long string of text that wont fit)
if you are not at the beginning take off the characters up to the space you found
add a newline (\n)
repeat
Like nedals said though, this may or may not correspond to where the lines were automatically wrapped by the textarea control, this is purely a user interface thing and the position of the breaks is not passed to the server when the form is submitted.
Incidentally, again as nedals said, what you are going to use the wrapped text for is critical, if you are going to put it in an email for example then the above method of chopping it into lines makes sense, but if you are going to show the message in a browser, you would probably be better letting the browser do the wrapping itself...
Bookmarks