Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing textarea data from form

Status
Not open for further replies.

HaroldMcF

MIS
Jul 29, 2002
8
0
0
US
I'm trying to create or replace a file with the contents of the textarea from an HTML form. I actually have it working okay except for a formatting problem.
The resulting file should have the same lines as the textarea information but it puts it all in one line.
I've tried putting the info into a variable (i.e. my $info = param("textareaname"). When I write $info to a file it is all one line, no.
I've tried putting the info into an array (i.e. my @info = param("textareaname") but that just results in $info[0] containing the whole text as one line and so writes it out as one line.
What I am doing is pulling an html file into the browser via a perl script and putting it into a textarea (correctly formatted) making changes and saving it back out with the changes. It all works but if you open the file in an editor it is all one long line and so not easy to debug.

Thanks for any help
 
If you check your textarea contents, there's probably no hard breaks, and what you're seeing is just the textarea wrapping.

If its really important to have a number of lines, then extract each line around the last whitespace of each line that is less than the width of the textarea

If you're only going to be populating teh textarea again, its going to look the same anyway

HTH
;P
 
Are you putting newlines in the textarea that aren't coming through when you get the file thru param()? That might happen if you're submitting the form via method=GET and not method=POST. I don't know how much auto-url-encoding browsers do.

Actually, are you getting the url-encoded line? With lots of % signs followed by a pair of hex characters? There's a couple of regular expressions that take care of that for you. I've got this laying around in use, but I'm not sure about why the last line is in there.
Code:
   my $value = param('textarea');
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/<!--(.|\n)*-->//g;
Hope it helps. ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top