Gossamer Forum
Home : Products : DBMan : Customization :

Checkbox with Images

(Page 1 of 2)
> >
Quote Reply
Checkbox with Images
Hello!
I tried to implement images beside checkboxes with the following code in the default.cfg.
On my local server it works fine but not on the internet:

Û_checkbox_fields = ( 'Topic Letters' => '<img src=./img/images1.gif alt=Image1>,<img src=\'./img/images2.gif\' alt=\'Image2\'>,<img src=\'./img/image3gif\' alt=\'Image3\'>'
);


When the script proceed I get the following code:
<INPUT TYPE="CHECKBOX" NAME="Topic Letters " VALUE="<img src='./img/image1.gif' alt='Image1'>"> <img src='./img/image1.gif' alt='Image1'>

Do you recognized the double > ' > Sign after Image1.
I tried many diffrent codes, but i coulnd`t find out to provide the second > Sign?
Any ideas?

thanX

Quote Reply
Re: Checkbox with Images In reply to
This would take a complete reworking of sub build_checkbox_fields. For one thing, I doubt that you want the image information written to your database. Or do you?


JPD
Quote Reply
Re: Checkbox with Images In reply to
I know that it should be
% _ checkbox _ fields
.... instead of
Û_checkbox_fields
Its this forum scripts default.
;-}


Quote Reply
Re: Checkbox with Images In reply to
yes, It could be written the image info to the db.txt.
any suggestions?


Quote Reply
Re: Checkbox with Images In reply to
I'm not sure that your images are going to print out with the way you have them defined. But I guess we can work on that later.

Add the following subroutine to db.cgi:

Code:

sub build_pic_checkbox_field {
# --------------------------------------------------------
# Builds a CHECKBOX field based on information found
# in the database definition. Parameters are the column to build
# whether it should be checked or not and a default value (optional).

my ($column, $values) = @_;

if (!$db_checkbox_fields{$column}) {
return "error building checkboxes: no checkboxes specified in config for field '$column'";
}

my @names = split (/,/, $db_checkbox_fields{$column});
my @values = split (/\Q$db_delim\E/, $values);
my ($name, $output);

foreach $name (@names) {
$pic = $name;
$pic =~ s/<img src=//;
$pic =~ s/>//;
(grep $_ eq $name, @values) ?
($output .= qq!<INPUT TYPE="CHECKBOX" NAME="$column" VALUE="$name" CHECKED> $pic\n!) :
($output .= qq!<INPUT TYPE="CHECKBOX" NAME="$column" VALUE="$name"> $pic\n!);
}
return $output;
}
To use it --

|; print &build_pic_checkbox_field("FieldName",$rec{'FieldName'}); print qq|

See if your graphics print out.

JPD
Quote Reply
Re: Checkbox with Images In reply to
thanX

I will try the script,
and give a feedback.



Quote Reply
Re: Checkbox with Images In reply to
I added the
sub build_pic_checkbox_field
subroutine between the sub main
and add_record subroutine in db.cgi

changed in html.pl
the checkbox line to the line you wrote above.

in default.cfg i didn?t changed anything, it looks like above:

% db _ checkbox_fields = ( 'Topic Letters' => '<img src=./img/images1.gif alt=Image1>,<img src=\'./img/images2.gif\' alt=\'Image2\'>,<img src=\'./img/image3gif\' alt=\'Image3\'>'
);

But there are no changes:

the processed code as again the > > signs:

I tried some other html-formating whitout quotes but no chance.
Always teh double > >.
Canīt belive this.

hlp plz

Quote Reply
Re: Checkbox with Images In reply to
Could I see your database in action?

JPD
Quote Reply
Re: Checkbox with Images In reply to
yes plz!

http://cityguide.virtualave.net/cgi-bin/dbman/db.cgi

viewing the records with imgs works fine, but
the imgs do not appear in the add, modify, search fields

the db which i uploaded there is the original dbman
with the typical file names:
default.db, default.cfg etc. etc.

CU?!

Quote Reply
Re: Checkbox with Images In reply to
I need to see the database that you have been working on.


JPD
Quote Reply
Re: Checkbox with Images In reply to
that is the db which I will be working on.
I havenīt start yet, because I need to know how or better if it is possible, to make checkboxes with imgs.

do you need to see the codes from the files?
should I send you the login and password?

CU
Quote Reply
Re: Checkbox with Images In reply to
I think I've got something worked out for you.

Instead of using Û_build_checkbox_fields, create another hash

Û_fancy_checkbox_fields = ( Popular => 'Yes|<img src="image1.jpg">,No|<img scrc="image2.jpg">' );

The syntax is

Fieldname => 'option1|image tag 1,option2|image tag 2[/green]');

Add the following subroutine to db.cgi:


sub build_fancy_checkbox_field {
# --------------------------------------------------------
# Builds a CHECKBOX field based on information found
# in the database definition. Parameters are the column to build
# whether it should be checked or not and a default value (optional).

my ($column, $values) = @_;

if (!$db_fancy_checkbox_fields{$column}) {
return "error building checkboxes: no checkboxes specified in config for field '$column'";
}

my @names = split (/,/, $db_fancy_checkbox_fields{$column});
my @values = split (/\Q$db_delim\E/, $values);

my ($name, $output);

foreach $name (@names) {
@data = split (/\Q$db_delim\E/, $name);
(grep $_ eq $data[0], @values) ?
($output .= qq!<INPUT TYPE="CHECKBOX" NAME="$column" VALUE="$data[0]" CHECKED> $data[1]\n!) :
($output .= qq!<INPUT TYPE="CHECKBOX" NAME="$column" VALUE="$data[0]"> $data[1]\n!);
}
return $output;
}


When you print out your checkbox field, use

print &build_fancy_checkbox_field("FieldName",$rec{'FieldName'});

(The forum software messes up the % sign. I don't know how to overcome that.)

JPD
Quote Reply
Re: Checkbox with Images In reply to
Thanky You! ;-}
I will try the script and tell you whats going on there.
I recognized too that the forum software messes up the % sign.
Just type % _fancy_etc_fileds =( ......
and give the users the tip not to leave space between the % and the subroutine.

CU
Deniz

Quote Reply
Re: Checkbox with Images In reply to
Hello JPDENI

almost ;-}

but there are some mini hooks!

I added an record an checked the yes and no boxes for one record
then i tried to search for the record where YES and NO(both) are checked
but the db couldn't find the record.
it is very necessary that it is possible to check more than 1 checkbox,
maybe up to 8 checkboxes for one record.


and the scond mini mini hook: I can see the imgs at the view/search screen
but not on the view results screen, (there stands only : YES|NO)
this is very important to see the imgs on the view results screen.

you helped me so much, I hope you can help me to fix this mini porblems too!

PS: I uploaded the db to:

http://cityguide.virtualave.net/cgi-bin/dbman/db.cgi
plz check!

Thank You
with respect
Deniz

Quote Reply
Re: Checkbox with Images In reply to
The best thing to do is to set up separate fields for each option.

However, if you don't want to do that, you can add the following to the beginning of sub query:

Code:

foreach $col (@db_cols) {
$in{$col} =~ s/~~/$db_delim/g;
}
That should fix your multiple selection problem

In Reply To:
and the scond mini mini hook: I can see the imgs at the view/search screen
but not on the view results screen, (there stands only : YES|NO)
this is very important to see the imgs on the view results screen.
Then you'll need to do some work to display the images.

Code:

|;
if ("Yes" =~ /$rec{'Popular'}) {
print qq|<img src="image1">|;
}
if ("No" =~ /$rec{'Popular'}) {
print qq|<img src="image2">|
}
print qq|
There may be another way of doing this, but I'll have to work on it later.


JPD
Quote Reply
Re: Checkbox with Images In reply to
thanks a lot JPDENI
I will try it!

Quote Reply
Re: Checkbox with Images In reply to
HelloJPDENI!
Everything works fine
multiple selection etc!
Thanks a lot!

But I donīt know how to implement your code above.
I tried the following code in the sub html_record (html.pl)but the generated page is blank!

I tried:

...
print qq||;
if ($rec{'Credit Cards'}) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="10%"><$font_color>Credit Cards:</FONT></TD>
<TD WIDTH="90%"> <$font>$rec{'Credit Cards'}|;if ("visa" =~ /$rec{'Credit Cards'}) { print qq|<img src="./img/visa.gif">|;}if ("aexpress" =~ /$rec{'Credit Cards'}) { print qq|<img src="./img/aexpress.gif">|}print qq|</Font></TD></TR>
|;
}


any suggestion?

CU?!
Deniz

Quote Reply
Re: Checkbox with Images In reply to
The whole page is blank? If so, you probably forgot to put in a closing </table> tag. Load the page again and check the source code for the page. (Right click on the page and select "View Source" from the menu that comes up.) If there's stuff in the source code, but not on the page, I can just about guarantee you forgot to close off your table.

If it's just that the images aren't showing up, try using the full URL to them instead of a relative URL. Also, many (most) servers do not allow images within the cgi-bin to be displayed. You may need to move them.


JPD
Quote Reply
Re: Checkbox with Images In reply to
HI!

there is an </table> close tag,
the html-source of the generated page looks like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
< H T M L > < H E A D >
< M E T A content="text/html; charset=windows-1252" http-equiv=Content-Type > < / H E A D >
< B O D Y > < / B O D Y > < / H T M L >

the server allows imgs in the cgi-bin,

Iīm not sure if the code in the sub html_record (html.pl)is correct implemented:
...
print qq||;
if ($rec{'Credit Cards'}) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="10%"><$font_color>Credit Cards:</FONT></TD>
<TD WIDTH="90%"> <$font>$rec{'Credit Cards'}|;if ("visa" =~ /$rec{'Credit Cards'}) { print qq|<img src="./img/visa.gif">|;}if ("aexpress" =~ /$rec{'Credit Cards'}) { print qq|<img src="./img/aexpress.gif">|}print qq|</Font></TD></TR>
|;
}

...
print qq|
</TABLE>
|;
}



Quote Reply
Re: Checkbox with Images In reply to
The code is correct, as far as it goes.

I need you to save your html.pl file to a web-accessible directory (one where you would place .html files) and rename it to html_pl.txt. Then come back here and tell me where I can pick it up. I'll take a look and see if I can figure out what's wrong.


JPD
Quote Reply
Re: Checkbox with Images In reply to
Hello!

I've uploaded db_cgi.txt, default_cfg.txt, html_pl.txt
and the modified dbman files to:

http://cityguide.virtualave.net/cgi-bin/dbman/
when you try to run: db.cgi you'll see the error msgs.

the code works fine without the red marked text, but without the text there are no imgs.

(html.pl)
...
print qq||;
if ($rec{'Popular'}) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="10%"><$font_color>Popular:</FONT></TD>
<TD WIDTH="90%"> <$font>$rec{'Popular'}|;if ("visa" =~ /$rec{'Popular'}) { print qq|<img src="./img/visa.gif">|;}if ("master" =~ /$rec{'Popular'}) { print qq|<img src="./img/master.gif">|}if ("diners" =~ /$rec{'Popular'}) { print qq|<img src="./img/diners.gif">|}print qq|</Font></TD></TR>
|;
}
print qq|
</TABLE>
|;
}

Ciao

Quote Reply
Re: Checkbox with Images In reply to
Now I'm confused again. Earlier you said that you just got a blank page. Now you say there are no images. Which is it?

JPD
Quote Reply
Re: Checkbox with Images In reply to
SORRY!
I donīt wanna make you confused.

without the red if-statements the code works fine,
including multiple selection etc. when I say there are no imgs , I mean there is only text in the view_result fields,

I double checked the code and if I try to access dbman
(including the red if-statements)
I get an error, you can see at the url:
http://cityguide.virtualave.net/cgi-bin/dbman/

I've uploaded db_cgi.txt, default_cfg.txt, html_pl.txt
and also the executable dbman-files.

Bye bye


Quote Reply
Re: Checkbox with Images In reply to
Things look okay.

Just to humor me, try using the full URL to the graphic instead of a relative one and see if that makes a difference.


JPD
Quote Reply
Re: Checkbox with Images In reply to
I found it. My fault.

Code:
if ("visa" =~ /$rec{'Popular'}/) {
print qq|<img src="./img/visa.gif">|;
}
if ("master" =~ /$rec{'Popular'}/) {
print qq|<img src="./img/master.gif">|;
}
if ("diners" =~ /$rec{'Popular'}/) {
print qq|<img src="./img/diners.gif">|;
}
JPD
> >