View Full Version : perl guru
very simple question I suppose for someone who knows cgi.
Basic form to email cgi script
having trouble with <textarea> output.
the html form contains:
<textarea name="message" wrap="true">..
perl script gets value from this textbox and outputs to email. The problem is how the hell can I make the script wrap the "message" before it outputs "message" to email. I get one long line in this field when it emails back to me. Any code I need to add to the script to make it "wrap" this field before outputting to email?
thanx in advance
Groovy
10-21-2001, 11:54 AM
geezzz...
might be simple for a real guru but not for me!!! :(
solution 1:
dont wrap, send in HTML.
html parser will do it.
solution 2:
wrap.
you need to know how long the line you want before wrapping it.
solution 3:
<textarea name="textfield" wrap="PHYSICAL"></textarea>
not sure about third one but i think thats the easiest way
Originally posted by run:
<STRONG>solution 1:
dont wrap, send in HTML.
html parser will do it.
solution 2:
wrap.
you need to know how long the line you want before wrapping it.
solution 3:
<textarea name="textfield" wrap="PHYSICAL"></textarea></STRONG>
solution 3 don't work - i tried 'physical" same thing.
the script processes it as text I suppose
I need solution 2, can you give more details?
yeah i know one way just let me think if theres anything better than i know, cuz its kinda long.
Third Os
10-21-2001, 12:27 PM
I had the same problem while writing a message board. The text from the textarea box was just one big line.
After taking a closer look at how it was saved, I saw that you need to edit the linebreaks a bit:
Before you output it in your mail, replace all the chr(10) chars to <br> tags.
If you can translate it from coldfusion, use this:
"#Replace(mailoutput, chr(10), '<br>','ALL')#"
That did the trick for me....
third os way might work only if you send in html.
i wrote a sub for you to convert the text. Im pretty positive theres an easier way to do it but at this moment i dont know.
sub wrap{
my ($txt, $len) = @_;
my ($w, $wrap, $thisLine);
foreach $w (split(/ /, $txt)){
if ($thisLine>$len){ $wrap .= "\n$w"; $thisLine = 0; }
else { $wrap .= "$w "; $thisLine += length($w); }
}
return $wrap;
}
oh by the way
$text = wrap($text, $preferred_length);
:)
brb, lol
Ok, by looking at the script, I think this subroutine splits up the lines:
sub decode_vars
{
$i=0;
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
foreach $item(@pairs) {
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$content=~s/\t/ /g;
$fields{$key}=$content;
if ($key eq "data_order") {
$content=~s/\012//g;
$content=~s/\015//g;
$content=~s/ //g;
$content=~s/ //g;
@sortlist=split(/,/,$content);
}
anything I need to add here?
sub wrap{
my ($txt, $len) = @_;
my ($w, $wrap, $thisLine);
foreach $w (split(/ /, $txt)){
$thisLine += length($w);
if ($thisLine=>$len){ $wrap .= "\n$w"; $thisLine = 0; }
else { $wrap .= "$w "; }
}
return $wrap;
}
this one is improved a bit.
for parisng input better use ReadParse() that comes with cgi-lib.pl.
salsbury
10-22-2001, 11:20 AM
here's how it is recommended in the perl manpage:
format =
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;< ~~
$_
.
$/ = '';
while (<> ) {
s/\s*\n\s*/ /g;
write FILEHANDLE;
}
(FILEHANDLE being the filehandle to your mail process) perl format stuff once you get used to it is pretty damn spiff.
vBulletin® v3.7.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.