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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text loses formatting. Perl or html problem?

Status
Not open for further replies.

marybailey

Programmer
Mar 14, 2002
47
US
I have a form to send email. In case you are interested, its at

There is a text area called personal message. When my client fills in this space with text that, say, has three bullet items, some indentations, spaces, <CR>s, all the formatting is lost.

Does anyone know if this is due to something in my html? Perhaps I have the textarea defined incorrectly?

Or is this happening in the perl script that sends the mail. The code for that follows. (Is there a better way to share this code?)

Thanks,
Mrs B

-------------PERL CODE FOLLOWS -------------------------

#!/usr/local/bin/perl
$mailprog = '/usr/lib/sendmail';

# Retrieve Date
&get_date;

# Parse Form Contents
&parse_form;

# Check Required Fields
&check_required;

# Send mail
&get_emails;

&do_work;

sub parse_form {

# Define the configuration associative array. #
%Config = ('jan','', 'feb','',
'mar','', 'apr','',
'may','', 'jun','',
'jul','', 'aug','',
'sep','', 'oct','',
'nov','', 'dec','',
'spec','', 'personalmsg','',
'emailsubject','');

# Determine the form's REQUEST_METHOD (GET or POST) and split the form #
# fields up into their name-value pairs. If the REQUEST_METHOD was #
# not GET or POST, send an error. #
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
# Split the name-value pairs
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);
}
else {
&error('request_method');
}

# For each name-value pair: #
foreach $pair (@pairs) {

# Split the pair up into individual variables. #
local($name, $value) = split(/=/, $pair);

# Decode the form encoding on the name and value variables. #
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;

# If they try to include server side includes, erase them, so they
# aren't a security risk if the html gets returned. Another
# security hole plugged up.
$value =~ s/<!--(.|\n)*-->//g;

# If the field name has been specified in the %Config array, it will #
# return a 1 for defined($Config{$name}}) and we should associate #
# this value with the appropriate configuration variable. If this #
# is not a configuration form field, put it into the associative #
# array %Form, appending the value with a ', ' if there is already a #
# value present. We also save the order of the form fields in the #
# @Field_Order array so we can use this order for the generic sort. #
if (defined($Config{$name})) {
$Config{$name} = $value;
}
else {
if ($Form{$name} && $value) {
$Form{$name} = &quot;$Form{$name}, $value&quot;;
}
elsif ($value) {
push(@Field_Order,$name);
$Form{$name} = $value;
}
}
}

# The next six lines remove any extra spaces or new lines from the #
# configuration variables, which may have been caused if your editor #
# wraps lines after a certain length or if you used spaces between field #
# names or environment variables. #
$Config{'required'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'required'} =~ s/(\s+)?\n+(\s+)?//g;
$Config{'env_report'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'env_report'} =~ s/(\s+)?\n+(\s+)?//g;
$Config{'print_config'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$Config{'print_config'} =~ s/(\s+)?\n+(\s+)?//g;

# Split the configuration variables into individual field names. #
@Required = split(/,/,$Config{'required'});
@Env_Report = split(/,/,$Config{'env_report'});


# ACCESS CONTROL FIX: Only allow ENV variables in @valid_ENV in #
# @Env_Report for security reasons. #
foreach $env_item (@Env_Report) {
foreach $valid_item (@valid_ENV) {
if ( $env_item eq $valid_item ) { push(@temp_array, $env_item) }
}
}
@Env_Report = @temp_array;
}


sub check_required {

$jan = $Config{'jan'};
$feb = $Config{'feb'};
$mar = $Config{'mar'};
$apr = $Config{'apr'};
$may = $Config{'may'};
$jun = $Config{'jun'};
$jul = $Config{'jul'};
$aug = $Config{'aug'};
$sep = $Config{'sep'};
$oct = $Config{'oct'};
$nov = $Config{'nov'};
$dec = $Config{'dec'};
$spec = $Config{'spec'};
$personalmsg = $Config{'personalmsg'};
$prob_list = &quot;&quot;;
$emailsubject = $Config{'emailsubject'};

sub do_work {

foreach $friend (@emailArr) {
open(MAIL,&quot;|$mailprog -t&quot;);
print MAIL &quot;To: $friend\n&quot;;
print MAIL &quot;From: $friend\n&quot;;
print MAIL &quot;Subject: $emailsubject\n&quot;;
print MAIL &quot;Content-Type: text/html; charset=us-ascii\n\n&quot;;
print MAIL &quot;<html>\n&quot;;
print MAIL &quot;<head>\n&quot;;
print MAIL &quot;</head>\n&quot;;
print MAIL &quot;<style>\n&quot;;
print MAIL &quot;</style>\n&quot;;
print MAIL &quot;<body>\n&quot;;
print MAIL &quot;<img src=\&quot;http:\/\/ print MAIL &quot;<P>&quot;;
print MAIL &quot;$Config{'personalmsg'}<\/B><\/I>\n&quot;;
print MAIL &quot;<P>\n&quot;;
print MAIL &quot;</body>\n&quot;;
print MAIL &quot;</html>\n&quot;;
close (MAIL);
}
}
 
That could be due to the textarea as well as the e-mail piece. To solve it from the textarea half of the puzzle, just add a wrap='hard' inside the textarea tag. This will keep all carriage returns the users place.

As for any bullet points, this could be also due to a user just copying and pasting some thing from a document that has this type of formatting. Since e-mail is strictly text-based, it does not handle any bullet points or special formatting (bolded words, colors, etc.). You might need to make your HTML page state to the user that if they want to use bullet points, they have to follow some simple rules to accomplish this (add in the <UL>, <LI>, </LI> and </UL>). Not pretty, but that's a limitation of text based messaging.

- Rieekan
 
I'll try it. The thing is, though, I see these textareas defined in other pages and they have wrap=virtual and they are sending it as it is seen - not pushing everythign together like mine is.

Mrs B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top