Loop through and display all checkbox options
Posted: 04 December 2010 08:01 PM   [ Ignore ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

I may have missed something obvious here but I can’t find a way to loop through all the options in a checkbox field and display each one.
At the moment i’m hardcoding each checkbox in the template like this:

<fieldset>
        <
label>Buyers will need:</label>
        <
label><input type="checkbox" class="checkbox" name="Photography" value="n" {Photography} />Photography</label
        <
label><input type="checkbox" class="checkbox" name="Illustration" value="n" {asset_required_extras}/>Illustration</label
        <
label><input type="checkbox" class="checkbox" name="Font licenses" value="n" {asset_required_extras}/>Font licenses</label
        <
label><input type="checkbox" class="checkbox" name="Icon licenses" value="n" {asset_required_extras}/>Icon licenses</label
</
fieldset

Which means if the clients choses to add another option from the control panel, the template will need to be edited.

I want to use these in a search / filter form to only show results with the selected attributes.

Thanks!

[ Edited: 04 December 2010 08:52 PM by jamestowers ]
Profile
 
 
Posted: 04 December 2010 09:19 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

It should look something like this:

<fieldset>
        <
label>Buyers will need:</label>
{options:asset_required_extra}
        
<label><input type="checkbox" class="checkbox" name="asset_required_extra[]" value="{option_value}" {checked} />{option_name}</label>
{/options:asset_required_extra}
</fieldset
Profile
 
 
Posted: 04 December 2010 09:27 PM   [ Ignore ]   [ # 2 ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

Perfect! Thank you.

Profile
 
 
Posted: 04 December 2010 09:34 PM   [ Ignore ]   [ # 3 ]
Is a Really Great Dancer
RankRank
Total Posts:  61
Joined  2010-12-03

Another quick question…

Is there a way to produces checkboxes from the options in a dropdown?

I have dropdown menu in the control panel so that members can assign the entry to a certain category, and I want to build a search form with all the categories listed as checkboxes so users can choose the categories they want to include in the search.

Profile