Gossamer Forum
Home : Products : DBMan : Installation :

Admin only fields & Select Fields

Quote Reply
Admin only fields & Select Fields
1. How can you make a checkbox, radio, textarea or select field admin only? OK, I found the answer to this one too, IF I don't use the auto generated forms. Is there anyway to do this with autogenerated forms?

Has anyone done anything slick like add a character to the form length field such that 35 would be a normal field length and 35a would be an admin only field length? This would get around the difficulty of using 0 for select, checkbox and radio fields and AxB for textareas etc, and -2 for admin only (and -1 for hidden). There could be a 0 and 0a (and AxB and Axba for textarea) Could the same thing be done for hidden fields? ) 0 and 0h, etc.?

I don't know a darn thing about cgi or perl, so maybe this isn't possible. But I sure need this capability -- hopefully without digging into html.pl

2. How can you set a select field to accept multiple choices? Found the answer to this question. Haven't tried it, but will. Thanks.

KISS. I can handle javascript and html, but have no experience with cgi/perl/unix. My prototype dbman is working, but I don't know how to make it do everything I have in mind. :-)

Thanks.

[This message has been edited by Warmfire (edited March 19, 1999).]



[This message has been edited by Warmfire (edited March 20, 1999).]
Quote Reply
Re: Admin only fields & Select Fields In reply to
I did it a different way. Set your admin-only fields to field length -2. Define your select fields, radio fields and checkbox fields the same way as normal. Also, set your textarea fields in a similar way (this would go in the .cfg file):

Code:
# Textarea fields. Field name => WIDTHxHEIGHT
%db_textarea_fields = ( Description => '40x3');

Then, in db.cgi replace sub build_html_record_form with the following:

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

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

The only thing this doesn't do is allow you to set the length of a text field on the form.

Since you say you have no experience in perl, I'll remind you that need to replace the entire subroutine, from the title to the last } before the next subroutine starts.


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