Gossamer Forum
Home : Products : DBMan : Discussions :

search for a check-box

Quote Reply
search for a check-box
I need something similar to the "validation" mod, but simpler. I have a checkbox field called "visible"... All default searches have the visible=1 appended in a hidden field and the admin can thus turn a record visibility on and off.

here are my questions:
1) is it possible to create a checkbox where it automatically enter a "0" or a "1" based on the checked status. I have played with the "0,1" settings:
Code:
'Visible' => [10, 'alpha', 0, 3, 1, '0', '1,0'],
%db_checkbox_fields = ('Visible' => '1,0');
but they don't seem to do the job


2) when I search with the check box unchecked hoping I will return all the invisible (0) records, it failed... I guess it has something to do with my first question....

3) is there a better way to do this... JPDeni's validation code incorporate sending email to form submitter of the validation, which I don't want, plus the use of a single radio button, making it not very easy to turn off, once on.

Thank you in advance
Quote Reply
Re: [Oink] search for a check-box In reply to
1) Taken from the FAQ regarding hiding a record:

Hide Record

Is there a modification for making it so that there's a checkbox when people add/modify records and that if it's unchecked, the record isn't shown in a search?

Response:
You could add a checkbox field to your database. I'll call it "ShowRecord" for illustrative purposes. You can call it anything you'd like, as long as you're consistent.

Define the checkbox as:

%db_checkbox_fields = ( ShowRecord => 'Yes' );

In db.cgi, sub view_records, at the beginning of the subroutine, add code:

unless ($per_admin) {
$in{'ShowRecord'} = "Yes";
}

This will let those with admin permission to view all records, but those without will only be able to view the ones that have the box checked. This will also apply to the owner of the record. The owner will be able to see his own record if he does a "modify" or "delete" though.

3) If you don't want to send an email when a record is validated just comment out the mail function lines within your db.cgi file.

Such as the lines that say: open (MAIL, "$mailprog") or &cgierr("unable to open mail program");

It is easy to modify the record and change the radio field to yes or no. Just make it an admin only field so that only you can make those changes. You might want to make your validation and your checkbox field mentioned above as viewable by admin only rather than a hidden field, so it is easy to make the change when needed.

--------------
P.S. Now that you have your database up and running you should post your questions in the customization forum :)

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] search for a check-box In reply to
Thank you.... I should have read the FAQ more thoroughly. I have implemented a text field for the moment (1,0). And it works. It seems that HTML checkboxes do not behave like they should (on/off), instead they recognize (on/null). I will search for an explanation online... I have also noted that check box state does not appear in the edit form... another HTML strangeness I assume. It will always appear unchecked unless I specify "checked", instead of reading value from the database.

The reason I am using a text field now is that if I use a check box, it will not allow me to do a (both on/off)search.

I will post further questions on the other forum.... though it name suggests "expert talk"...
Quote Reply
Re: [Oink] search for a check-box In reply to
before anyone has a chance to tell me off.... I found this in another forum
Code:
if ($in{'ReceiveMail'} eq "Yes") {
my $radio_button = qq|Receive Mail:
<input type="radio" name="ReceiveMail" value="Yes" checked> Yes
<input type="radio" name="ReceiveMail" value="No"> No;
}
else {
my $radio_button = qq|Receive Mail:
<input type="radio" name="ReceiveMail" value="Yes"> Yes
<input type="radio" name="ReceiveMail" value="No" checked> No;
}

I have never used checkbox or radio button before.... unlike textfields, which can show the value of the field, checkbox and radio button don't interact with the value in the database at all!! After 6 years of HTML :)
Quote Reply
Re: [Oink] search for a check-box In reply to
I myself would set this up using a radio field rather than a checkbox:

In your .cfg file define the field like this:

'visible' => [20,'alpha',0,3,1,'Yes','Yes|No'],

%db_radio_fields = ( 'visible' => 'Yes,No' );

Then in your sub html_record_form setup your field something like this:

<TR><TD colspan=2><$font><B>Visible?</B> &nbsp; &nbsp; |; print &build_radio_field("visible",$rec{'visible'}); print qq|</font></TD></TR>

Then in your sub html_record or sub html_record_long use this:

if ($rec{'visible'} eq "Yes") {
print qq| WHATEVER YOU WANT TO SHOW |;
}

Then in sub html_view_search after:

<input type=hidden name="uid" value="$db_uid">
add:

<INPUT TYPE=HIDDEN NAME="visible" VALUE="Yes">

I think this will give you the results you are looking for. If not let me know and we will work with you till you get the results you need.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/