Gossamer Forum
Home : Products : DBMan : Discussions :

build_checkbox_field question

Quote Reply
build_checkbox_field question
I use print &build_checkbox_field ($counter, "$rec{'$counter'}"); in a loop to show fields numbered 1 to 99 as configured in the cfg.
When checking the boxes of a specific record in html_record_form, the checked boxes are activated as normally and checked items are saved to the db and html_record shows the checked items. Everything is OK that long.

The problem:

When re-entering html_record_form for a specific record, the previously checked boxes are NOT checked as default, so I have to re-check them when editing the record.

In other words, it seems as build_checkbox_field does not pull out the variables from the db.

Very thankful for your help is yours

CSky
Quote Reply
Re: [seasky] build_checkbox_field question In reply to
until Paul crusise by ...

I remember over at the unofficial faq there were questions/solutions to something like what you're asking.

... the phrases to look for might be radio / check boxes ... somebody wanted to get car options or something like that ... actually, I think that there were also fruit being used as examples.

Sorry for not being able to provide more help.

Good luck

openoffice + gimp + sketch ... Smile
Quote Reply
Re: [seasky] build_checkbox_field question In reply to
How are the fields stored?........is it yes/no or 1/0 ?

You'd basically need to loop though the database and put an if/else inside the loop like:

Code:
if ($data[$db_check_field_number] eq 'yes') {
check the tickbox/radio
}
else {
make a blank one
}
Quote Reply
Re: [seasky] build_checkbox_field question In reply to
Thank you, guys, but I think I need more exact and more practical advices. Can you tell me how to use things TOGETHER with the looped &build_checkbox_field ($counter, "$rec{'$counter'}");

CSky

Quote Reply
Re: [seasky] build_checkbox_field question In reply to
Probably, if we could see the code you are using.
Quote Reply
Re: [RedRum] build_checkbox_field question In reply to
Of course! Here it is:

This is in html_record_form:

if ($per_admin) {
print qq|
<tr><td colspan="2" align="center"><br>
<TABLE CELLPADDING=1 CELLSPACING=0 BORDER=0>
|;


for (0 .. 19) {
print qq|<tr>|;
for (0 .. 4) {
$counter2 = $counter2+1;
$counter = $counter+1;
print qq|<td align="left" valign="top"><$font>|;
print &build_checkbox_field ($counter,"$rec{'$counter'}");
print qq|$rec{'$counter'}</td>|;
}

print qq|</tr>|;
}

print qq|
</table>
</td></tr>
|;
}


This is in %db_checkbox_fields:

%db_checkbox_fields = (

'1' => 'ng-001',
'2' => 'ng-002',
'3' => 'ng-003',
'4' => 'ng-004', etcetera

And this is in db_def:

1 => [14, 'alpha', 0, 255, 0, '', ''],
2 => [15, 'alpha', 0, 255, 0, '', ''],
3 => [16, 'alpha', 0, 255, 0, '', ''],
4 => [17, 'alpha', 0, 255, 0, '', ''], etcetera...

I hope you can cope with this rather unusual way of looping (which shouldn't be the issue of it not working)

Thanks and greetings
CSky

Last edited by:

seasky: Oct 15, 2001, 8:16 AM
Quote Reply
Re: [seasky] build_checkbox_field question In reply to
Nobody discovered it, but &build_checkbox_field ($counter, "$rec{'$counter'}"); should have been &build_checkbox_field ($counter, "$rec{$counter}"); without single-quotes. It was that easy...

Greetings
CSky

Quote Reply
Re: [seasky] build_checkbox_field question In reply to
I might have seen it if I'd have found this post ....doh.

Just incase you were wondering why.....

Single quotes stop scalars/hashes/arrays etc....being interpreted.

So....

my $var = 'HELLO';

print '$var';

....would print $var......but

print "$var";

....would print HELLO as would:

print $var;

It's the same with hashes.....

%hash = (HELLO => 'GOODBYE');

$hash{$var} would print GOODBYE, but $hash{'$var'} would not exist so it would print nothing.

Last edited by:

RedRum: Oct 22, 2001, 6:52 AM