Gossamer Forum
Home : Products : Links 2.0 : Customization :

Modifying add form in admin in Links2.0b5

Quote Reply
Modifying add form in admin in Links2.0b5
I am running links 2.0b5 and want to know how to modify the add form in the admin program and also the modify form thinger... I want to add another field in it but can locate where to edit it. Any help would be appreciated. All I really need to know is what file(s) and where in the file(s). Thanks!

Regards,
Brian
Quote Reply
Re: Modifying add form in admin in Links2.0b5 In reply to
  mjordn12 take a look at your admin_html.pl Smile

------------
Joe Thong
http://elara.hypermart.net/
Quote Reply
Re: Modifying add form in admin in Links2.0b5 In reply to
Thanks Joe! I found it, but have no idea where to go from here-

Code:
sub html_add_form {
# --------------------------------------------------------
# The add form page where the user fills out all the details
# on the new record he would like to add. You should use
# &html_record_form to print out the form as it makes
# updating much easier. Feel free to edit &get_defaults
# to change the default values.

&html_print_headers();
print qq|
<html>
<head>
<title>$html_title: Add a New $html_object.</title>
</head>

<body bgcolor="#DDDDDD">
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$in{'db'}">
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Add a New $html_object</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Add a New $html_object
</b></font></center><br>
<$font>
|; &html_record_form (&get_defaults); print qq|
</font></p>
<p><center> <INPUT TYPE="SUBMIT" NAME="add_record" VALUE="Add $html_object"> <INPUT TYPE="RESET" VALUE="Reset Form"></center></p>
|; &html_footer; print qq|
</td></tr>
</table>
</form>
</body>
</html>
|;
}

It looks like I need to edit &get_defaults, but I have no idea what that is or where it is...

Regards,
Brian

[This message has been edited by mjordn12 (edited February 19, 1999).]
Quote Reply
Re: Modifying add form in admin in Links2.0b5 In reply to
mjordn12,

No, you do not need to edit the get_default sub in db_utils.pl since it will handle the defaults automatically.

The default for a field is handled by the record definition in links.def in the variable %db_def which looks like this:

Quote:
%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']
);

The column on the left of the => is the field name. On the right side of the =>, inside the brackets from left to right, you have the field number, sort type, length of the input window in a form (used in the forms created in the admin screen), maximum length of the field itself, whether it should not be null (1 = cannot be null, 0 = can be null), the default value for the field if any, and a perl regexp that describes the default form of the field (if any).

You might also take a look at the %add_system_fields and %db_select_fields in links.def.

Once you have your new field defined, you need a way to add it to all the records already in links.db. What I do is use the upgrade.pl script that comes with the beta. I modify it to match what I want to add. For example, I added a date field to my database that was to keep track of the date a resource was originally added (v2.0 changes the other date anytime a record is modified by a user -- but not the admin). I changed:

Quote:
while (<DB> ) {
chomp;
s/NULL//g;
print DBOUT "$_|0|0|Yes\n";
}

to read:

Quote:
LINE: while (<DB> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@rec = &split_decode($_);
$rec[$db_dateadded] = $rec[$db_modified];
print DBOUT &join_encode(&array_to_hash(0, @rec));
}

I put this script in my admin/data directory, chmod it to 755, and then ran it. It updated my links.db just fine, but stored it as links2.db so that I could check it before renaming it to links.db.

Once you have done all that, you can modify the forms used in add/modify to include <input> tags for the new fields.

I hope this helps.

------------------
Bob Connors
bobsie@orphanage.com
www.orphanage.com/goodstuff/


[This message has been edited by Bobsie (edited February 19, 1999).]
Quote Reply
Re: Modifying add form in admin in Links2.0b5 In reply to
Bobsie, let's just say I wanted to add a field called 'generic'...how would I code that on the db_utils file?

------------------
Regards,
Brian
mjordn12@aol.com
veggietales.virtualave.net/veggielink/ (MegaLinks2.0)


[This message has been edited by mjordn12 (edited February 19, 1999).]
Quote Reply
Re: Modifying add form in admin in Links2.0b5 In reply to
As I said, you do not do anything in db_utils.pl. Your defaults are defined in the record in links.def. All db_utils.pl does it look at the record definition for the defaults, if any, and puts them in the field input form. However, if you are building your own input form, you have to specify the default yourself in the input tag by using the value= parameter.

------------------
Bob Connors
bobsie@orphanage.com
www.orphanage.com/goodstuff/
Quote Reply
Re: Modifying add form in admin in Links2.0b5 In reply to
Oooohhhhh, Ok cool. Thats great! Thanks man! You're the best!

------------------
Regards,
Brian
mjordn12@aol.com
veggietales.virtualave.net/veggielink/ (MegaLinks2.0)

Quote Reply
Re: Modifying add form in admin in Links2.0b5 In reply to
Does this work the same way in Links 2 final version as well? I am trying to add a Comments field and Language field. Most of the instructions I think I understand, but adding the additional fields to the links.db is where I'm lost. How do I get it to add 2 new fields at once? Will the instructions for using upgrade.pl work with a links 2 database?