Gossamer Forum
Home : Products : DBMan : Customization :

radio to checkbox on search

Quote Reply
radio to checkbox on search
i have a field setup as radio so user can select only one option easily. i like this because they can see all choices without opening a select option list.

when i search, i want the radio field to be setup as a checkbox field so user can search for more than one option at one time (matching any selected options). any suggestions? thanks
Quote Reply
Re: [delicia] radio to checkbox on search In reply to
Under html_record_form try the following:

if ($html_view_search) {print checkbox stuff} else {print radio button stuff}

Add in your code and give it a try...
Quote Reply
Re: [Watts] radio to checkbox on search In reply to
thanks, but i want to use autogenerate code. i cannot get autogenerate to build checkboxes from the choices.
Quote Reply
Re: [delicia] radio to checkbox on search In reply to
Are you opposed to modifying the code at all? If you do auto-generate you'll still have to make a change to default.cgi and default.pl (one time only though).
Quote Reply
Re: [Watts] radio to checkbox on search In reply to
i'm happy to modify the autogenerate code. i just don't want to have to modify the html_record and html_record_form in html.pl for every database i do! thanks.
Quote Reply
Re: [delicia] radio to checkbox on search In reply to
Try this... I haven't tested it, but in db.cgi modify the following line:

sub build_radio_field {
# --------------------------------------------------------
# Builds a RADIO Button field based on information found
# in the database definition. Parameters are the column to build
# and a default value (optional).

my ($column, $value) = @_;
my (@buttons, $button, $output);

@buttons = split (/,/, $db_radio_fields{$column});

if ($#buttons == -1) {
$output = "error building radio buttons: no radio fields specified in config for field '$column'!";
}
else {
foreach $button (@buttons) {
$value =~ /^\Q$button\E$/ ?
($output .= qq|<INPUT TYPE="|; if ($in{'view_search'}) {print qq|CHECKBOX|;} else {print qq|RADIO|;} print qq|" NAME="$column" VALUE="$button" CHECKED> $button \n|) :
($output .= qq|<INPUT TYPE="|; if ($in{'view_search'}) {print qq|CHECKBOX|;} else {print qq|RADIO|;} print qq|" NAME="$column" VALUE="$button"> $button \n|);
}
}
return $output;
}
Quote Reply
Re: [Watts] radio to checkbox on search In reply to
Didn't work... hang on.... don't try the above example...
Quote Reply
Re: [Watts] radio to checkbox on search In reply to
Okay this works... same concept as above:

sub build_radio_field {
# --------------------------------------------------------
# Builds a RADIO Button field based on information found
# in the database definition. Parameters are the column to build
# and a default value (optional).

my ($column, $value) = @_;
my (@buttons, $button, $output);

@buttons = split (/,/, $db_radio_fields{$column});

if (($in{'view_search'}) || ($in{'view_records'})) {
$radiocheck = "CHECKBOX";
} else {
$radiocheck = "RADIO";
}




if ($#buttons == -1) {
$output = "error building radio buttons: no radio fields specified in config for field '$column'!";
}
else {
foreach $button (@buttons) {
$value =~ /^\Q$button\E$/ ?
($output .= qq|<INPUT TYPE="$radiocheck" NAME="$column" VALUE="$button" CHECKED> $button \n|) :
($output .= qq|<INPUT TYPE="$radiocheck" NAME="$column" VALUE="$button"> $button \n|);
}
}
return $output;
}


The only problem is when you search you have to check the "Match Any" checkbox or else the search see the checkboxes as "Item and Item" instead of "Item or Item".

Perhaps the answer lies the sub_build_checkbox routine?
Quote Reply
Re: [Watts] radio to checkbox on search In reply to
thanks!!! that's what i was looking for. the search form looks great.

unfortunately, the search isn't working. i tried both putting a hidden field for match any and manually checking the match any check box. neither worked.......

Last edited by:

delicia: Aug 18, 2003, 1:05 PM
Quote Reply
Re: [delicia] radio to checkbox on search In reply to
Perhaps the URL being created is too long?

Consider posting the URL that is failing to search and I'll have a look at it.