Gossamer Forum
Home : Products : Links 2.0 : Customization :

Allowing line breaks in fields

Quote Reply
Allowing line breaks in fields
By default, Links removes line breaks in a field. That might make sense in standard fields, but is there a way to keep line breaks from a form input, that is, have them converted to a <p>?

This will be useful for the Detailed pages.

I know I can manually input a <p>, but I would prefer a solution where that's not needed.

Cheers
John
Quote Reply
Re: Allowing line breaks in fields In reply to
OK, I didn't catch this when searching before I posted the above question, but found it when doing a new search:

In http://www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/001265.html
phonix suggests:

Quote:
# Format Comment input so that it will fit nicely in the database
if ($in{$db_cols[$db_comment]}) {
$in{$db_cols[$db_comment]} =~ s/\n\n/<br><br>/g;
$in{$db_cols[$db_comment]} =~ s/\n/<br>/g;
}

This might do the trick. However, that's for the add.cgi. What about the admin add function? Where to add the blurb then?

John

[This message has been edited by gotze (edited May 08, 1999).]
Quote Reply
Re: Allowing line breaks in fields In reply to
Have you looked at sub linewrap in db_utils.pl? It might be better suited for your needs.
Quote Reply
Re: Allowing line breaks in fields In reply to
I have tried that, and it doesn't work :-(

The line breaks are in the database - I can see them when looking at a record in the admin section. But they are stripped out when building pages.

In db_utils.pl, just before sub load_template, I added:

Quote:
if ($in{$db_cols[$db_article]}) {
$in{$db_cols[$db_article]} =~ s/\n\n/<p>/g;
$in{$db_cols[$db_article]} =~ s/\n/<br>/g;
}

I also tried adding the above bit of code at various places, also in nph-build.cgi, but it's all the same result - no breaks.

Could it be that there is something wrong with that code? I have added a field called Article, and added
Quote:
$db_article = 14;
to the list of important fields in the links.def.

What is wrong?
Quote Reply
Re: Allowing line breaks in fields In reply to
How are you specifying the <input> tag for the article field in your add form?
Quote Reply
Re: Allowing line breaks in fields In reply to
Dunno! I'm working within the admin section. Where do you specify the forms there?

Anyway, I don't think it's the input form that's the problem. If I add a new record with a longer 'article' with line breaks, it saves OK. If modifying the record, the line breaks are there.
They are just not there when building the pages.
Quote Reply
Re: Allowing line breaks in fields In reply to
What I would do is in site_html_detailed (in either site_html.pl or site_html_templates.pl depending on whether you are using templates or not) is to add:

$rec{'FieldName'} =~ s/\n/<br>/g;

to change all line feeds to html line break tags.

Just a note, Links doesn't strip out any characters, it's just that browsers don't display extra white space, you need to convert line feeds to <br> tags which browsers understands.

Hope that helps,

Alex
Quote Reply
Re: Allowing line breaks in fields In reply to
Thanks Alex,

That was that problem solved. Watch out for an upcoming, innovative use of Links ;-)

John
Quote Reply
Re: Allowing line breaks in fields In reply to
Thanks for the suggestion, Alex. I'd been just manually adding my <BR> tags in the admin fields rather than typing with line breaks.

Phoenix
Quote Reply
Re: Allowing line breaks in fields In reply to
can anyone suggest how I can get the line breaks shown in the admin view... at the moment it still looks like one big body of text...

thanks
DM
Quote Reply
Re: Allowing line breaks in fields In reply to
I know this is an ancient post but, thank you Wink

------------------------------
my detailed page - still under construction
http://bartour.hypermart.net/links2/pages/Detailed/3.html

Quote Reply
Re: Allowing line breaks in fields In reply to
Does anyone know how this sort of thing can be adapted for widgetz's review.cgi script ie so that a line break is auto converted into <P> ?

------------------
http://www.freeontheweb.com/
Reviewed and rated resources for webmasters
-------------------------