Gossamer Forum
Home : Products : DBMan : Customization :

How do I show line breaks in a text area field?

Quote Reply
How do I show line breaks in a text area field?
I have tried adding the text below (as the FAQ suggests) but it doesn't work for me. In place of the line breaks being displayed, I get `` or ````.

Am I on the right track, that I insert the line stated as a new line in the sub-routine sub_html_record? And that the result should be two line breaks in succession being displayed as a paragraph break when the record is displayed? Presumably, the same change can be made in sub_html_record_form so that the paragraph break shows up in the form display?

TIA,

Andy

A. In html_record, after

my (%rec) = @_;

add

$rec{'fieldname'} =~ s/\n/<BR>/g;
Added: 25-Jun-1999
Quote Reply
Re: How do I show line breaks in a text area field? In reply to
In sub split_decode in db.cgi there is a line that subsititutes a linefeed character for the `` that is saved into the record.

$array[$i] =~ s/``/\n/g; # Change '' back to newlines..

I suppose if, for some reason that isn't happening, you could use

$rec{'fieldname'} =~ s/``/<BR>/g;

You might try putting both things in, if you're having problems.

Regarding the form, the line breaks should show up, again because of the line in sub split_decode. If not, I suppose you could use
$rec{'fieldname'} =~ s/``/\n/g;
before the textarea.
------------------
JPD







[This message has been edited by JPDeni (edited June 27, 1999).]
Quote Reply
Re: How do I show line breaks in a text area field? In reply to
Let's be sure we're talking about the same thing here. You have used both `` and '' to refer to the characters. I guess I'm a stickler for details, but I need to be sure we're on the same page.

The script converts all newline characters to `` when the record is saved and then converts it back to a newline character when it is decoded in sub split_decode.

Did you check to make sure you have the line I mentioned in sub split_decode?

Version 2.04 is the most recent version.

Have you made any other modifications to the script?


------------------
JPD





Quote Reply
Re: How do I show line breaks in a text area field? In reply to
Thanks, JPD, for the script amendment -- and for walking me through how the line breaks should be turned into '' and then back to line breaks.

Unfortunately, the script additions (and the standard sub-routines) are doing nothing to convert the '' back to line breaks.

I'm running DBMan version 2.04 -- could it be there's an enhancement I'm missing or should I try something else?!

TIA,

Andy
Quote Reply
Re: How do I show line breaks in a text area field? In reply to
Thanks again, JDP.

Yes, and sorry, I do mean `` in each instance.

The line in sub split_decode is there, as follows:

$array[$i] =~ s/``/\n/g; # Change '' back to newlines..

While I've modified the .pl script (but only intending to change the textual instructions to the user), I've done nothing to db.cgi except alter for the location of script. Could an unintentional change to the .pl script be the cause of this problem?

Since your posting, I have now carried out a fresh download and replaced the existing db.cgi -- but no joy I'm afraid.

Many thanks,

Andy
Quote Reply
Re: How do I show line breaks in a text area field? In reply to
This is extremely confusing.

Try this, just for debugging purposes.

In sub html_record, just after

my (%rec) = @_;

add

$rec{'fieldname'} =~ s/``/fred/g;

This is just to see if any substitution is being done at all.


------------------
JPD





Quote Reply
Re: How do I show line breaks in a text area field? In reply to
I have tried this, but get NO substitution.

Just the good old ```` where 2 line breaks had been input originally.

I'm at a loss. Could I have messed up the .pl file? Is there a reason the substitution in dg.cgi (definitely unchanged) isn't working? Hoping there's a solution...

TIA,

Andy
Quote Reply
Re: How do I show line breaks in a text area field? In reply to
Well, that tells us something, although I'm not sure what.

It's not that your db.pl (or db.cgi) script is messed up. Your script isn't even reading a Perl command.

I think it's time for me to take a look at your html.pl file. Please copy it to a web-accessible directory (one where you would place html files) and rename it to html_pl.txt. Then come back and let me know where it is. I'll take a look at it.


------------------
JPD





Quote Reply
Re: How do I show line breaks in a text area field? In reply to
Thanks.

I have placed the file html_pl.txt in the root directory at http://www.globalcustody.net/

If there's an error I've created by my inexperience, I hope you find it without too much bother -- and apologies!

It'll be great to get this problem solved, as I'd like to get using the script on our site which is soon to go commercial with, hopefully, our first paid-for ad banner!

All the best,

Andy
Quote Reply
Re: How do I show line breaks in a text area field? In reply to
Ah. Now I got it.

In the original FAQ, as you quoted, it says

$rec{'fieldname'} =~ s/\n/<BR>/g;

What it doesn't say (and probably should) is that you need to replace fieldname with the name of the field you're dealing with.

So, if the field is named "Description" in your .cfg file, you would use

$rec{'Description'} =~ s/\n/<BR>/g;

Try that. If it doesn't work, try the codes I listed in my first message to you.


------------------
JPD





Quote Reply
Re: How do I show line breaks in a text area field? In reply to
JPD, thanks.

We're halfway there! Entering the name of the field and using the "\n" variant, i.e.
$rec{'Text'} =~ s/\n/<BR>/g;
works with sub html_record_form. The result is that a paragraph (i.e. double line) break entered in the form appears in the form display with a paragraph break. When going back to edit the text, "<BR><BR>" appears in the form.

With sub_html record, the "\n" and "``" variants used together do not work. Here's an extract from the script:
my (%rec) = @_;
$rec{'Text'} =~ s/\n/<BR>/g;
$rec{'Text'} =~ s/``/<BR>/g;
# Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record(%rec) and return);

If you need to take a look, the full script is at http://www.globalcustody.net/html_pl.txt

All the best,

Andy
Quote Reply
Re: How do I show line breaks in a text area field? In reply to
Whoops!

I've just realised that I'm using another script to display the database contents in a tabular format. The change now made to the .pl means that the DBMan form is laid out with a paragraph break. But the final HTML page shows ````.

Is there a straightforward adjustment to the script to replace `` with <BR> (or perhaps better still, to replace ```` with <P> ) in the database?

All the best,

Andy
Quote Reply
Re: How do I show line breaks in a text area field? In reply to
You might have to manually edit your .db file to make changes in records already in there.

Look in db.cgi for sub join_encode

Change

$tmp =~ s/\n/``/g; # Change newline to `` symbol.

to

$tmp =~ s/\n\n/<P>/g;
$tmp =~ s/\n/<BR>/g;

Possibly if you make one more change you won't have to manually edit the .db file. Just below sub join_encode is sub split_decode.

You could try changing

$array[$i] =~ s/``/\n/g; # Change '' back to newlines..

to

$array[$i] =~ s/````/<P>/g; # Change '' back to newlines..
$array[$i] =~ s/``/<BR>/g; # Change '' back to newlines..

I ain't gonna guarantee a thing, cause I haven't tested it. But it seems like it might work.


------------------
JPD





Quote Reply
Re: How do I show line breaks in a text area field? In reply to
Yes!!

That works. The database now has "<P>" in place of ````.

Thanks also for the further script. As my understadning is poor, I've simply used "find & replace" to add "<P>" in place of "````".

I really appreciate your help.

Thanks,

Andy
Quote Reply
Re: How do I show line breaks in a text area field? In reply to
I do modify with this step below,but how to get rid of br tag in the texarea of modify_form

Look in db.cgi for sub join_encode

Change


$tmp =~ s/\n/``/g; # Change newline to `` symbol.


to


$tmp =~ s/\n\n/<P>/g;
$tmp =~ s/\n/<BR>/g;


Possibly if you make one more change you won't have to manually edit the .db file. Just below sub join_encode is sub split_decode.

You could try changing


$array[$i] =~ s/``/\n/g; # Change '' back to newlines..


to


$array[$i] =~ s/````/<P>/g; # Change '' back to newlines..
$array[$i] =~ s/``/<BR>/g; # Change '' back to newlines..


I dont sure what step am I forgot because
it work fine ,.db file has br tag
everywhere I type enter.
the result of record is fine,it has breakline,But when I login to modify I dont want -<BR>-
show in the texarea form just want it show like what the user typed in add_form,i mean

text
text

not

text -<BR>- text


it should as this thread when edit my message in the texarea has no br tag . how to get rid of br tag in the texarea of modify_form
Sorry for my bad english,hope you understand what i mean, and thank for any help replied