Gossamer Forum
Home : Products : Gossamer Links : Discussions :

What is the best way of doing checkboxes?

Quote Reply
What is the best way of doing checkboxes?
I'm about to add some more data for the links records on our site, it will contain the following options for the user to choose from (they can and probably will choose multiple options, so this should probably be checkboxes, but advise if other).
Code:

Format:
Select each game format that your deck is allowed to play in by ticking the appropriate box

[ ] Standard Type II
[ ] Extended Format
[ ] Legacy Format
[ ] Tribal Wars Standard
[ ] Vintage Format
[ ] Prismatic Format
[ ] Singelton Format
[ ] Tribal Wars Classic
[ ] Online Classic
[ ] Pauper Format


So, my questions:
1. They will likely have multiple answers that they want to input, do I create a field in the Links table that is a checkmark field? And then add each one of the options listed above in the form names and form values? (I assume yes)

2. After someone has chosen multiple answers from the above list, how do I properly format the output on the detailed.html page?
What would the coding be for the include.form.html template so that when they come back to modify their listing the check boxes are already checked for the options they checked when they first added the listing? What is the best way to list the output on the detailed.html template so that it formats nicely and shows all the options that they selected?


3. What would be the coding to display the chosen options on the detailed.html template? I don't know how the info is stored in the database when multiple options are selected, so for all I know its stored as a giant run on sentence if they selected all the options (which is possible) so if I write it on the detailed.html template as simply
Code:

Deck Formats: <%game_formats%>

It might just display as
Deck Formats: Extended Format Legacy Format Standard Type II Vintage Format Online Classic Format
Which is going to look really whacked.

So I need to know what the best way is for lisiting the output on the detailed.html page when a user has selected multiple options in the include_form.html template.


4. Is there a better option than checkboxes for doing this kind of field in the database? Maybe a multi-select selection list?
If so an example of the best way to list the chosen options on the detailed.html template would be helpful as would a code snippet of how to write the multi-select selection list for the include_form.html template so that if they modify their listing later the options they chose originally in the multi-select selection list are already chosen for them when they return to modify the listing.



Please don't waste your time writing out the complete coding for all the options above when giving examples of what the coding is for the detailed.html template to display the chosen options nor for the include_form.html template. Just give me the coding for one or two options so that I have the starting point and I'll take it from there.

I know it's a lot of questions, but checkmark boxes and multi-select selection lists have never been my thing in Links, so I've always avoided using them in the past years.

Thanks,

Last edited by:

Westin: May 12, 2009, 5:43 AM
Quote Reply
Re: [Westin] What is the best way of doing checkboxes? In reply to
Yup, checkboxes will be ok for that.

To format on detailed.html, just use a new global:

format_checkboxes
Code:
sub {
my @split = split /\n/, $_[0]
return { checkbox_loop => \@split }
}

..then call with:
Code:
<%format_checkboxes($Field_Name)%>
<%if checkbox_loop.length%>
<%loop checkbox_loop%>
<%loop_value%> <%if not last%> , <%endif%>
<%endloop%>
<%endif%>

(NB: untested, but should work)

For include_form.html - just use ULTRAGlobals (amazing what it does ;))

Code:
<div class="row clear">
<label for="Contact_Name" class="name">Testing Checkboxes:</label>
<div class="value">
<%Plugins::ULTRAGlobals::Format_Checkbox_Field('Testing123')%>

<%loop checkbox_loop%>
<input name="<%field_name%>" id="<%value%>" type="checkbox"value="<%value%>" <%if selected%>checked<%endif%> />
<label for="<%value%>"><%name%></label>
<%endloop%>
</div>
</div>

Just change "Testing123" to whatever your field name is. This will also work for modify.cgi, and pre-select the values for the user.

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!

Last edited by:

Andy: May 12, 2009, 7:06 AM
Quote Reply
Re: [Andy] What is the best way of doing checkboxes? In reply to
Is there anything that UltraGlobals can not do!

Thanks, I'll have a go at it and see what comes of it. Might be interesting or at the least change my mind about avoiding using checkbox fields in the future.

Last edited by:

Westin: May 12, 2009, 7:03 AM
Quote Reply
Re: [Westin] What is the best way of doing checkboxes? In reply to
Oh, what do I name that first global in the code you gave above?
Quote Reply
Re: [Westin] What is the best way of doing checkboxes? In reply to
Westin wrote:
Oh, what do I name that first global in the code you gave above?

Sorry, put the [code] tags around too much text =)

Should have been:

format_checkboxes
Code:
sub {
my @split = split /\n/, $_[0];
return { checkbox_loop => \@split }
}


..so call the global "format_checkboxes"

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!

Last edited by:

Andy: May 12, 2009, 7:16 AM
Quote Reply
Re: [Andy] What is the best way of doing checkboxes? In reply to
Unable to compile 'format_checkboxes': syntax error at (eval 58) line 3, near "] return" Global symbol "@split" requires explicit package name at (eval 58) line 3. syntax error at (eval 58) line 4, near "} }"
Quote Reply
Re: [Westin] What is the best way of doing checkboxes? In reply to
Oops, please try the updated code above (was missing a ;)

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: [Andy] What is the best way of doing checkboxes? In reply to
Works great except that the checkboxes that were checked when they submitted the listing are not checked when the person goes and modifies their listing. I have this on the include_form template:

Code:
<div class="row required clear">
<label for="Description" class="nicetext">Deck Formats:<br></label>
<div class="value">
<%Plugins::ULTRAGlobals::Format_Checkbox_Field('deckformats')%>

<%loop checkbox_loop%>
<input name="<%field_name%>" id="<%value%>" type="checkbox"value="<%value%>" <%if selected%>checked<%endif%> />
<label for="<%value%>"><%name%></label>
<%endloop%>
</div>
</div>
Quote Reply
Re: [Westin] What is the best way of doing checkboxes? In reply to
What form values do you have? (for both fields, required by checkboxes)

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: [Andy] What is the best way of doing checkboxes? In reply to
Standard
Extended
Block
Two-Headed Giant
Vintage
Legacy
Freeform (MTGO)
Classic (MTGO)
Prismatic (MTGO)
Singleton 100 (MTGO)
Tribal Wars Classic (MTGO)
Tribal Wars Standard (MTGO)
Momir Basic (MTGO)
Commander (MTGO)
Pauper (MTGO)
Kaleidoscope (MTGO)
Quote Reply
Re: [Westin] What is the best way of doing checkboxes? In reply to
MMm, my reply didn't post for some reason :/

You need this:

<%Plugins::ULTRAGlobals::Format_Checkbox_Field('deckformats',$deckformats)%>

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!