Gossamer Forum
Home : Products : Links 2.0 : Customization :

Adding fields for dummies??

Quote Reply
Adding fields for dummies??
After spending a whole day searching and searching this forum and the web for a simple explanation of how to add a new field to my page I’ve come to a rather stressed conclusion that it does not exist.

After searching this forum for ‘add fields’ in the ‘Links 2.0 Customization Forum’ I do get several results but none that are clearly understandable or are complete. The FAQ section does no better.

The most frustrating point is that most of the threads end with somebody saying ‘search the forum for how to add new fields’ sending me back to square one and chasing my own tail again (arggghhh).

In a bid to save my own sanity and hopefully clear this up once and for all here is what I’m trying to do (bare in mind that I am no perl genius when replying with your answers)

I have the standard fields at the moment (title, url, description etc) allowing people to add their link and would like to add another to the list. My site is music based and I allow dj’s to add a link to a Real Audio Mix they have online. I wish to add a drop down field where the user can select the quality of their recording when submitting (32.5 Kbps, 20.7 Kbps etc)

I have made alterations to the script before and have done so successfully so I’m hoping this shouldn’t be too difficult.

One thing that might be worth mentioning is that I do not use the templates but use the site_html.pl.

If somebody could please tell me the name of the files that need to be edited (links.def, site_html.pl, etc) and perhaps show me some kind of code that can be cut and pasted into them this would be so so helpful.

My links forum is located at www.netmix.com/bpm/v4/audio

Paul @ BPM


Paul Wright
www.djsource.co.uk
Quote Reply
Re: Adding fields for dummies?? In reply to
OK, here we go ... since you don't have a large links.db as of yet, I am going to tell you a low-tech way of doing it, which requires you to update your databse by hand. This could be done with a script, but is not worth it in your case.

Backup your files.

Open your links.def

Change
In Reply To:
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [6, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [8, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [9, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [10, 'alpha', 0, 5, 0, 'No', ''],
Rating => [11, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [12, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes']
);
to
In Reply To:
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],

'Real Audio Mix' => [6, 'alpha', 40, 75, 1, 'http://', ''],
'Real Audio Type' => [7, 'alpha', 40, 75, 1, 'http://', ''],

'Contact Name' => [8, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [9, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [10, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [11, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [12, 'alpha', 0, 5, 0, 'No', ''],
Rating => [13, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [14, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [15, 'alpha', 10, 10, 1, 'Yes', 'No|Yes']
);
Still in links.def, change
In Reply To:
# Field Number of some important fields. The number is from %db_def above
# where the first field equals 0.
$db_category = 4; $db_modified = 3; $db_url = 2;
$db_hits = 8; $db_isnew = 9; $db_ispop = 10;
$db_contact_name = 6; $db_contact_email = 7; $db_title = 1;
$db_votes = 12; $db_rating = 11; $db_mail = 13;
to
In Reply To:
# Field Number of some important fields. The number is from %db_def above
# where the first field equals 0.
$db_category = 4; $db_modified = 3; $db_url = 2;
$db_hits = 10; $db_isnew = 11; $db_ispop = 12;
$db_contact_name = 8; $db_contact_email = 9; $db_title = 1;
$db_votes = 14; $db_rating = 13; $db_mail = 15;
$db_realaudiolink = 6; $db_realaudotype = 7;
Further down, change
In Reply To:
%db_select_fields = (
isNew => 'Yes,No',
isPopular => 'Yes,No',
ReceiveMail => 'Yes,No'
);
to
In Reply To:
%db_select_fields = (
'Real Audio Type' => '32.5 Kbps, 20.7 Kbps',
isNew => 'Yes,No',
isPopular => 'Yes,No',
ReceiveMail => 'Yes,No'
);
Now, on to site_html.pl
(well, I haven't worked with this for a long time, so I might have missed something ...)

In sub site_html_link add something like:
if ($rec{'Real Audio Mix'}) { $output .= qq~ <a class="link" href="$rec{$db_realaudiolink}">Get Real Audio Mix</a> ($rec($db_realaudiotype)~; }
after
if ($rec{'isPopular'} eq "Yes") { $output .= qq~ <small><sup class="pop">pop</sup></small>~; }

In sub site_html_add_form
add

<tr><td align="right" valign="top">Real Audio Mix Link:</td>
<td><input name="Real Audio Mix" value="$in{'Real Audio Mix'}" size="50"></td></tr>
<tr><td align="right" valign="top">Real Audio Type:</td>
<td>~; print &build_select_field ("Real Audio Type", "$in{'Real Audio Type'}"); print qq~</td></tr>

After
<tr><td align="right" valign="top">Description:</td>
<td><textarea wrap="virtual" name="Description" value="$in{'Description'}" rows="3" cols="42">$in{'Description'}</textarea></td></tr>

Hmmm ... I'm not sure if that's right, but it should give you an idea ...

Last, but not least, you need to edit your links.db.

You will need to add two pipes, ||, after the descriptions, in each line. Yes, it's a mess in there, but it's not too bad Wink

I think that should do it. Good luck.
Quote Reply
Re: Adding fields for dummies?? In reply to
Wow, this is exacly what I was after thanks (huge sigh of relief!)

I'll give it a go now and post how I get on later.

thanks again

Paul

Paul Wright
www.djsource.co.uk
Quote Reply
Re: Adding fields for dummies?? In reply to
Well I've installed all the changes and I can't belive it but it worked first time.

I decide against having a drop down option for one of the categories and opted for the more conventional field where people can enter in their own data. This was mainly due to the fact that I don't know what software people will be using to create their real audio files. Apart from that though all is working fine in the world of Links 2.0

Thanks again

Paul @ BPM

Paul Wright
www.djsource.co.uk
Quote Reply
Re: Adding fields for dummies?? In reply to
Cool



Quote Reply
Re: Adding fields for dummies?? In reply to
What (if any) changes must be employed to this method when adding fields while using templates?

Quote Reply
Re: Adding fields for dummies?? In reply to
For templates, you don't edit site_html.pl. Nor do you need to edit site_html_templates.pl. All you have to do is to use the <%YourNewField%> in your link.html, and to add it to your add.html, add_success.html and add_error.html.

Also, you need to hand-edit your links.db, or use the script found in the resource center.