Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Help!? Checkbox values on page!

Quote Reply
Help!? Checkbox values on page!
I need some help with a checkbox values:

I have a checkbox field / column in my database called "Site_Type". There are several different values on this "Site_Type" field. Such as "free", "blog", "resource" etc..

It works just fine if I use <%Site_Type%> on a template page, it then shows all values for this column / field.

So if a link has the option "free" and "blog" selected on this field, they both show up on template.

BUT I need to be able to configure each of the values for "Site_Type" differently.

What I want is:

<%if Site_Type eq 'Free'%><a href="/free.html">Free</a><%endif%>
<%if Site_Type eq 'Blog'%><a href="/blog.html">Blog</a><%endif%>

BUT

It does NOT work if 2 or more values are selected in "Site_Type".

It does work if only 1 value is selected in "Site_Type".


How can I make it show up all values using a IF tag? Am I using the wrong tags?

Thanks
Quote Reply
Re: [demon] Help!? Checkbox values on page! In reply to
Hi Demon,

Try it like this

<%if Site_Type like 'Free'%><a href="/free.html">Free</a> <%else%>
<%if Site_Type like 'Blog'%><a href="/blog.html">Blog</a><%endif%>

P.S. also I think you you do have not to use else statement. Just test it see.

Hope this helps.

Vishal

Vishal
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Help!? Checkbox values on page! In reply to
Hi, thanks for your reply!

I tried that, but I should have mentioned that it would look like this with more than 2 options:

<%if Site_Type like 'Free'%><a href="/free.html">Free</a> <%endif%>
<%if Site_Type like 'Blog'%><a href="/blog.html">Blog</a><%endif%>
<%if Site_Type like 'option3'%><a href="/option3.html">Free</a> <%endif%>
<%if Site_Type like 'option4'%><a href="/option4.html">Blog</a><%endif%>

Does the else tag work with more than 2 options? When I tried it seemed to not to work since there could be more than 1 or 2 options selected at the same time and it would simply show nothing instead..

You see what I mean?
Quote Reply
Re: [demon] Help!? Checkbox values on page! In reply to
Just remove else tag and type in endif tag and see if it works.

If not, then I can I can look for another post - which I believe is somewhere on this forum.

Vishal
-------------------------------------------------------
Quote Reply
Re: [demon] Help!? Checkbox values on page! In reply to
Hi,

A more complex solution, is to make an "array" out of those options. i.e;

Code:
<%globa_name($Site_Type)%>
sub {
my $tmp = $_[0];
my @array = split /\n/, $tmp;
my @new_array;
foreach (@array) {
chomp;
my $tmp_hash;
$tmp_hash->{value} = $_;
push @new_array, $tmp_hash;
}
return { Site_Type_Loop => \@new_array }
}

..and then "loop" with;

Code:
<%if Site_Type%>
<%loop Site_Type_Loop%>
<%if value eq 'Free'%><a href="/free.html">Free</a>
<%elsif value eq 'Blog'%><a href="/blog.html">Blog</a>
<%elsif value eq 'option3'%><a href="/option3.html">Free</a>
<%elsif value eq 'option4'%><a href="/option4.html">Blog</a>
<%endif%>
<%endloop%>
<%endif%>

Hope that helps Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [SWDevil.Com] Help!? Checkbox values on page! In reply to
Hi,

Yes I already tried that with only endif tags.. This works fine if only 1 option is selected but when more than 1 option selected it does not work at all. Only show blank. Seems as the IF tags only work if its either or so to speak.

THanks again for your input!
Quote Reply
Re: [Andy] Help!? Checkbox values on page! In reply to
Thanks Andy! I will try that and see if it works.

I did the elseif before but not with the help of a global. Didnt work.. But maybe it will with the help of the global and loop it will.

Will let you know! Thanks!
Quote Reply
Re: [Andy] Help!? Checkbox values on page! In reply to
I just tried it and it works perfectly!

Thanks for your help!
Quote Reply
Re: [demon] Help!? Checkbox values on page! In reply to
Hi,

No problem Cool

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!