Gossamer Forum
Home : Products : DBMan : Customization :

Discriminate field display

Quote Reply
Discriminate field display
In case it is of use to anyone who is still (like me) struggling with DBMan in ignorance of perl, I thought I might share the following customisation that I have just written for my database:
I needed to prevent certain fields showing in both the short and long forms for records of companies who have not paid a premium price. Upon payment, these fields would then appear. My method for this was to set up a new field, in which the administrator could enter the word Yes, and then include a test for the word. If the word Yes is not in that field, then the special fields would not be displayed. This enables me to set up all the data in the database at the outset, but control how it is subsequently displayed.

The code is quite simple, and will be obvious to all the perl experts out there.

In your db.cfg add the field definition:

Sub => [17,'alpha',5,5,0,'','Yes']

The field number will vary, of course, as may its name.

In html.pl place the following lines around the field that needs to be hidden:

in sub html_record_long:

|;
if ($rec{'Sub'}eq"Yes") {
print qq|

[here is the hidden field]

|;
}
print qq|

Do the same for any fields in the form, and the same in the short form.

I hope this is useful to someone.

If you want to leave the table formatting unchanged, simply place the code around the field variable - $rec{'Field_name'} and this will print a blank field.
If you want to exclude entire rows place the code before the <tr> and after the </tr> surrounding the rows.

To hide the "Yes" field in all input forms from all but the administrator (to prevent sneaky people enabling it themselves!), do the following:
Insert a blank row immediately before the line in your sub html_record_form, then type:

|;
if ($per_admin) {
print qq|

The following may be the row in question:
<tr>
<td ALIGN="Right" VALIGN="TOP" width="95"><p align="right"><$font>Sub:</font></td>
<td VALIGN="TOP" colspan="3" width="599"><p align="left"><$font><input NAME="Sub"
VALUE="$rec{'Sub'}" SIZE="20" MAXLENGTH="5" tabindex="18"></font><font SIZE="1"></font></td>
</tr>

After this row type:

|;
}
print qq|


After this, printing will follow as before.

Only when logged in as an admin will you be able to see that field.



David Olley
Anglo & Foreign International Limited,
Winchester
England