0

I've got a safecracker form which edits a channel entry. I want to display the categories that have been selected for the entry through check boxes, I've used this code:

{categories show_group="13"}
   <input type="checkbox" name="category[]" id="{category_name}" value="{category_id}"{checked}> {category_name}<br>
{/categories}

Which works fine, the checkboxes that have been previously selected are showing up as selected, but it's ignoring the 'show_group="13"' parameter. It's showing all a categories for that channel but I just want it to show the category group 13.

I'm not sure where I'm going wrong? From the documentation it looks like I've got the right parameter, and 13 is definitely to category group id.

Is there any other way of displaying the categories selected for a certain category id for an entry?

Thanks, Julie

1

A work-around is to use conditionals when displaying the categories, and set hidden form fields for any categories from other groups to preserve them when they're checked.

{categories}
  {if '{category_group_id}'=='13'}
    <input type="checkbox" name="category[]" id="{category_name}" value="{category_id}"{checked}> {category_name}<br>
  {/if}
  {if "{category_group_id}" != '13' && '{checked}' != ""}
    <input type="hidden" name="category[]" value="{category_id}"><br>
  {/if}
{/categories}

ps. you can use {categories group_id="xx"}...{/categories} to limit to a category group, but from my tests, that doesn't seem to preserve any categories from other groups that might already have been selected.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.