Gossamer Forum
Home : Products : DBMan : Discussions :

Formatting question

Quote Reply
Formatting question
Hi!

I have a field that includes lots of text, i e a textarea. When displaying this field I want hard wrapping to appear, for instance even if the content is "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" (no spaces, it should be broken down to the specified width and display "xxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx".

This can obviously be done by using a textarea tag in the output as well, but that doesnt look too good.

Is there any tags or other solution to do this within a TD?

Thanks!!

Quote Reply
Re: Formatting question In reply to
In the textarea tag use wrap="virtual" and then use regex:

s/\n/< br >/g;

...which replaces a newline with a br tag for displaying on a html page. You'd need to remove the spaces in the br tag - they are there to stop the forum taking it literally.

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: Formatting question In reply to
Cool!

So s/\n/< br >/g; goes as is within the textarea tag? Smart.

Quote Reply
Re: Formatting question In reply to
No that code goes in db.cgi before the record gets displayed.

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: Formatting question In reply to
Check the FAQ:
http://www.gossamer-threads.com/...s/Detailed/1035.html


- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Formatting question In reply to
Thanks a lot!!

This solves most of it. There is one tricky left though... if the user enters a very long string without spaces, for instance "blablablablablablablablablablablablablablablablablablablablablablablablablabla"... this doesnt break anywhere.

Possible to solve? Thanks! :)

Quote Reply
Re: Formatting question In reply to
This _may_ work...

Code:
my @lines = split /\n/, $rec{'Description'}; # Split the description at each \n and store in @lines
foreach (@lines) { # Loop through @lines
if (length($_) > 20) { # If length of line > 20...
s/(.{10})/$1<BR>/g; # Split it into 10 char chunks
}
$_ .= "<BR>"; # Append a br tag to every line
$rec{'Description'} .= $_; # Re-join for storage within DBMAN
}
Installations:http://www.wiredon.net/gt/

Quote Reply
Re: Formatting question In reply to
This will stop anyone from entering words that are longer than a set number of chars in length.
I found 25 to be ok. If the try and enter words that are longer then it will return an error.
The problem I found with trying to limit the length of the line is that lower case is shorter than upper case.
ie,
aaaaaawwwwwwmmmmmm
AAAAAAWWWWWWMMMMMM
therefore, 20 chars of upper case can be a lot longer than 20 of lower. This also applies to different fonts.
Put this at the top of sub validate_record in your db.cgi,

$descr = $in{'Description'};
$descr =~ s/\s+/ /g;
$descr =~ /^\s+(.+)$/ ? ($descr = $1) : ($descr = $descr);
@words = split(/\s/,$descr);
foreach (@words) {
unless ($_ =~ /^\S{1,25}$/) {
push(@input_err, "$col <font face=arial,verdana,helvetica,sans serif size=2
color=ce0000><b>You have words that are too long in your description field.
You are not allowed to enter words that are longer than 25 characters in length. Check
your Description field and shorten any words that are to long.</b>");
last;
}
}


Bob
http://totallyfreeads.com

Quote Reply
Re: Formatting question In reply to
Uppercase aren't always longer - it works both ways.

I think you can shorten that code too:

Code:
my @words = split /\W+/, $in{'Description'};
Code:
foreach (@words) {
if (length($_) > 25) {
push @input_err, "Word too long : ($_)":
}
}
Installations:http://www.wiredon.net/gt/

Quote Reply
Re: Formatting question In reply to
Well it realy depends on the font you use. Courier or Courier New has the same spacing between upper and lower case. Dam uguly font though, but there is a big difference between the most commonly used fonts, Ariel, Verdana, Helvetica ect, which if entered in a continious line can distroy your table formatting and the look of your page.
Try it in your word processor.

Bob
Quote Reply
Re: Formatting question In reply to
Thanks!

This works just like I wanted it to! However... :) I also want to use it for the Private Emailer Mod (a sendmail like mod within DB Man) and cant get it to work.

I thought I would be able to use the same code at top of sub send_email, but it just gets "ignored"...

sub send_email {
# --------------------------------------------------------
# This subroutine added for the private email mod
#

$descr = $in{'emailmessage'};
$descr =~ s/\s+/ /g;
$descr =~ /^\s+(.+)$/ ? ($descr = $1) : ($descr = $descr);
@words = split(/\s/,$descr);

foreach (@words) {
unless ($_ =~ /^\S{1,25}$/) {
push(@input_err, "$col <font face=arial,verdana,helvetica,sans serif size=2
color=ce0000><b>You have words that are too long in your description field.
You are not allowed to enter words that are longer than 25 characters in length. Check
your Description field and shorten any words that are to long.</b>");
last;
}
}

unless ($in{'email'}) { $message = ".<BR>"; }
unless ($in{'email'} =~ /.+\@.+\..+/) { $message = "Your email address is incorrect.<BR>"; }
unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "You must enter a message.<BR>"; }
%rec = &get_record($in{$db_key});
if (!%rec) { $message .= "The email address you requested could not be found.<BR>"; }
elsif (!$rec{$db_email_field}) { $message .= "There is no email address on file for this person.<BR>" }
if ($message) {
chomp($message);
&html_send_email_form($message);
return;
}
open (MAIL, "$mailprog") || &cgierr("unable to open mail program");
print MAIL "To: $rec{$db_email_field}\n";
print MAIL "From: $in{'email'}\n";
print MAIL "Subject: $in{'subject'}\n";
print MAIL "Content-Type: Text/Html\n\n";
print MAIL "<HTML><DIV>\n";
$in{'emailmessage'}=~s/\n/
/g;
print MAIL $in{'emailmessage'};
print MAIL "</DIV></HTML>";
close (MAIL);
&html_send_email_success;
}


Quote Reply
Re: Formatting question In reply to
hmm... I have another question - this time only for the send_email part. Is there a way to take out any HTML tags within the message? This works fine within DB Man.

Thanks!