Gossamer Forum
Home : Products : DBMan : Customization :

Custom field "label" mod

Quote Reply
Custom field "label" mod
I looked through the mods and didn't see anything on this...

Is there a mod for the autogenerated forms that will allow you to define your own custom field "labels." For example, when you use the autogenerated forms, each data entry box is labeled with the field name. I'd like a little more flexability to have custom labels displayed next to the data entry box.

If I have a field named "Description" and the add page is autogenerated, the user will be presented with a text area titled "Description." I'd like to be able to enter a custom label for that field that reads "Type in the event details here" instead of just using the field name. This is just an example.

I like using the autogenerated forms because there is virtually no setup required and I don't need the forms to look nice (not that they don't). However, it would be nice to be able to define custom labels in the cfg file to add that extra custom look.
Quote Reply
Re: [acravens] Custom field "label" mod In reply to
Can't guarantee this will work but give it a try - you'll need to do some hacking and change things in more than one place (especially in db.cgi) - save a back up copy before tweaking the script.

Change this (in default.cfg):

Code:
# Database Definition
# --------------------------------------------------------
# Definition of your database. Format is
# field_name => ['position', 'field_type', 'form-length', 'maxlength', 'not_null', 'default', 'valid_expr']

%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 255, 1, '', ''],
URL => [2, 'alpha', 40, 255, 1, 'http://', '^http://'],
Type => [3, 'alpha', 0, 60, 1, '', ''],
Date => [4, 'date', 12, 15, 1, &get_date, ''],
Category => [5, 'alpha', 0, 255, 1, '', ''],
Description => [6, 'alpha', '40x3', 500, 0, '', ''],
Validated => [7, 'alpha', 0, 3, 1, 'Yes', 'Yes|No'],
Popular => [8, 'alpha', 0, 3, 0, '', ''],
Userid => [9, 'alpha', -2, 15, 0, '', '']
);



to this:
Code:
# Database Definition
# --------------------------------------------------------
# Definition of your database. Format is
# field_name => ['position', 'field_type', 'form-length', 'maxlength', 'not_null', 'default', 'valid_expr', 'description']

%db_def = (
ID => [0, 'numer', 5, 8, 1, '', '', 'this is the ID'],
Title => [1, 'alpha', 40, 255, 1, '', '', 'this is the title'],
URL => [2, 'alpha', 40, 255, 1, 'http://', '^http://', 'this is the URL'],
Type => [3, 'alpha', 0, 60, 1, '', '', 'this is the type'],
Date => [4, 'date', 12, 15, 1, &get_date, '', 'this is the Date'],
Category => [5, 'alpha', 0, 255, 1, '', '', 'this is the category'],
Description => [6, 'alpha', '40x3', 500, 0, '', '', 'this is the description'],
Validated => [7, 'alpha', 0, 3, 1, 'Yes', 'Yes|No', 'this is validated'],
Popular => [8, 'alpha', 0, 3, 0, '', '', 'this is popular or not'],
Userid => [9, 'alpha', -2, 15, 0, '', '', 'this is the username - it may not always show']
);


2. Change this:
Code:
# ===========================================================================
# Build up some variables from your definitions. Internal use only.
foreach (sort { $db_def{$a}[0] <=> $db_def{$b}[0] } keys %db_def) {
push (@db_cols, $_);
$db_sort{$_} = $db_def{$_}[1];
$db_form_len{$_} = $db_def{$_}[2];
$db_lengths{$_} = $db_def{$_}[3];
$db_not_null{$_} = $db_def{$_}[4];
$db_defaults{$_} = $db_def{$_}[5];
$db_valid_types{$_} = $db_def{$_}[6];
($_ eq $db_key) and $db_key_pos = $db_def{$_}[0];
}

to this:

Code:
# ===========================================================================
# Build up some variables from your definitions. Internal use only.
foreach (sort { $db_def{$a}[0] <=> $db_def{$b}[0] } keys %db_def) {
push (@db_cols, $_);
$db_sort{$_} = $db_def{$_}[1];
$db_form_len{$_} = $db_def{$_}[2];
$db_lengths{$_} = $db_def{$_}[3];
$db_not_null{$_} = $db_def{$_}[4];
$db_defaults{$_} = $db_def{$_}[5];
$db_valid_types{$_} = $db_def{$_}[6];
$db_description{$_} = $db_def{$_}[7];
($_ eq $db_key) and $db_key_pos = $db_def{$_}[0];
}


Then modify this sub in db.cgi by sticking $db_description{$field} wherever you want the description to display (see bolded part for example)


sub build_html_record_form {
# --------------------------------------------------------
# Builds a record form based on the config information.
#
my (%rec) = @_;
my ($output, $field);

$output = "<p><table border=0>";
foreach $field (@db_cols) {
if ($db_select_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_select_field($field, $rec{$field}) . "</td></tr>"; }
elsif ($db_radio_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_radio_field($field, $rec{$field}) . "</td></tr>"; }
elsif ($db_checkbox_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_checkbox_field ($field, $rec{$field}) . "</td></tr>"; }
elsif ($db_form_len{$field} =~ /(\d+)x(\d+)/) {
$output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%><textarea name="$field" cols="$1" rows="$2">$rec{$field}</textarea></td></tr>~; }
elsif ($db_form_len{$field} == -1) { $output = qq~<input type=hidden name="$field" value="$rec{$field}">$output~; }
elsif ($db_form_len{$field} == -2) { $per_admin ? ($output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%><input type=text name="$field" value="$rec{$field}" maxlength="$db_lengths{$field}"></td></tr>~) :
($output = qq~<input type=hidden name="$field" value="$rec{$field}">$output~); }
else { $output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%> $db_description{$field} <input type=text name="$field" value="$rec{$field}" size="$db_form_len{$field}" maxlength="$db_lengths{$field}"></td></tr>~; }
}
$output .= "</table></p>\n";
return $output;
}

Last edited by:

Watts: Jan 14, 2005, 4:20 PM
Quote Reply
Re: [Watts] Custom field "label" mod In reply to
Thank you... it works as advertised! I'll just need to move the new label information so it prints out along the top of the data entry field instead of the left side. That should not be a big deal though.

Thanks again.