0

I want my users to be able to post articles so I'm using channel:form to accomplish this, everything's working great but I can't work out how to output categories as checkboxes, I have two category groups that i'd like to output separately, the code i've tried either outputs all categories or none.

I have the following code:

{exp:channel:form channel="work" return="contribute/thanks"}
          <p>
            <label for="title">Title</label>
            <input type="text" name="title" id="title" value="{title}" size="50" maxlength="100" onkeyup="liveUrlTitle();">
            <input type="hidden" name="url_title" id="url_title" value="{url_title}" maxlength="75" size="50">
          </p>
<h2>Formats</h2>
          {categories}
            {if category_group_id == 4} {!-- formats --}
            <label class="checkbox">{category_name}
            <input type="checkbox" id="{category_id}" name="{category_id}[]" value="">
            </label>
            {/if}
          {/categories}

          <h2>Industries</h2>
          {categories}
            {if category_group_id == 1} {!-- industries --}
            <label class="checkbox">{category_name}
            <input type="checkbox" id="{category_id}" name="{category_id}[]" value="">
            </label>
            {/if}
          {/categories}

          <p><input type="submit" name="submit" value="Submit"></p>

{/exp:channel:form}

This isn't outputting any categories, seems it's not understanding the if statements? However if I use the code shown on the example (http://ellislab.com/expressionengine/user-guide/add-ons/channel/channel_form/#categories)

<label for="categories">Categories</label>
<select name="category[]" id="categories" size="4" multiple="multiple">
  {categories}
    <option value="{category_id}"{selected}>{category_name}</option>
  {/categories}
</select>

This outputs all of the categories into one select dropdown, i'm struggling to see how to adapt this, any ideas would be most appreciated!

2 Answers 2

1

First u can use (show_group) param in your {categories} loop instead off {if} condition

      {categories show_group="4"}
        ......
      {/categories}

      {categories show_group="1"}
        ......
      {/categories}

and if you want to use {if} condition then change your code to :

      {categories}
        {if {category_group_id} == 4} {!-- formats --}
        ......
        {/if}
      {/categories}

      {categories}
        {if {category_group_id} == 1} {!-- formats --}
        ......
        {/if}
      {/categories}

the trick here is to around category_group_id variable with parentheses.

Note: this hack is in EE2.8.0 in another version maybe the line number will be different.

Regard's.

0
0

Like this for category group with checkbox using Channel Form

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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