Gossamer Forum
Home : Products : DBMan : Customization :

Re: [kd4rdb] hidden fields / not keeping track of all fields in a database in html form.

Quote Reply
Re: [kd4rdb] hidden fields / not keeping track of all fields in a database in html form. In reply to
In my database, I need to create limited forms that do not contain all the fields in a record. For example, in my database I keep track of equipment issued to various members of our group. The equipment database is quite extensive and contains relatively static fields such as equipment name, serial number and the barcode that is attached. But in day to day use, all my users need to do is change one field... who it is assigned to. The way I'm doing the assigning is to generate a pick list for each piece of equipment when I do a "list all". The pick list contains a pre-fab'ed URL. Problem is.... what if someone changes the barcode attached to the radio at the same time I'm choosing a person to assign it to? Let's say the pre-fab'ed URL is 5 minutes old, and someone made a change to the serial number of the radio AFTER my prefabb'ed URL was generated. If I submit the prefabbed URL, the serial number field in my record goes back to it's original value. It would be better if I could just submit a form that ONLY contained the fields I intended to change and not ALL of the fields as dbman requires now.
I gave this some thought and realized that there is a difference between NOT including a field in the URL submitted and including blank data in a field. In the normal DBMan, a --- represents a null value and is stripped out in the sub parse_form. What I've done is to make any field that is blank in the submitted URL contain ---, and postpone removing the --- until the sub join_encode.
The slick part about this mod is that it allows you to create a VERY short form without having to hide the fields (ie input type="hidden"). You must include the db_key field (such as ID for example) and atleast one other field. All other fields that are NOT listed in your form will maintain the values they presently have in the database.
Presently the only problem yet to be solved is that fields that are NOT_NULL and are not included in the submitted URL will cause the database to generate a %fieldname% cannot be blank message during the sub validate_record. I have a solution in mind, but have not implemented it yet.

All of these changes are made to db.cgi.
In sub parse_form after line:
$value =~ s/<!--(.|\n)*-->//g;
add:
if ($value eq "" ) {
$value="---";
}

and comment out:
# if ($value eq "---" ) { next PAIR; }

In sub modify_record after line:
# If we have userid's and this is not an admin, then we force the record to keep it's own
# userid.
if ($auth_user_field >= 0 and (!$per_admin or !$in{$db_cols[$auth_user_field]})) {
$in{$db_cols[$auth_user_field]} = $data[$auth_user_field];
}
add:
$count=0;
foreach $col (@db_cols) {
$value=$data[$count];
$count=$count+1;
$tmp = $in{$col};
if ($tmp eq ''){
$in{$col}=$value;
}
}
and finally in sub join_encode after line:
$tmp =~ s/\n/``/g; # Change newline to `` symbol.
add:
$tmp =~ s/---//g; # Change newline to `` symbol.
Subject Author Views Date
Thread hidden fields / not keeping track of all fields in a database in html form. kd4rdb 2931 Dec 4, 2006, 8:25 PM
Post Re: [kd4rdb] hidden fields / not keeping track of all fields in a database in html form.
JPDeni 2864 Dec 5, 2006, 10:42 AM
Thread Re: [kd4rdb] hidden fields / not keeping track of all fields in a database in html form.
kd4rdb 2847 Dec 26, 2006, 8:50 PM
Post Re: [kd4rdb] hidden fields / not keeping track of all fields in a database in html form.
JPDeni 2832 Dec 27, 2006, 4:12 AM