Answers.Body: <p>The first loop you're using loops over <code>entry.gistCategories.options</code>, which contains all the options available. However, in the second loop (when <code>entry.gistCategories|length !== 0</code>), you're only looping over the options that have been selected.</p>
  
  <p>Try this:</p>
  
  <pre><code>{% if entry.gistCategories | length == 0 %}
      &lt;ul&gt;
          {% for option in entry.gistCategories.options %}
              {# output checkboxes #}
          {% endfor %}
      &lt;/ul&gt;
  {% else %}  
      &lt;ul&gt;
          {% for checkboxOption in entry.gistCategories.options %}
              {# output checkboxes #}
          {% endfor %}
      &lt;/ul&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-17T20:58:52.070Z
Answers.LastActivityDate: 2015-02-17T20:58:52.070Z
Answers.UserDisplayName: Keith Bartholomew
Answers.Body: <p>Since the form was already submitted, your code is only looping through the checkboxes that were checked.</p>
  
  <p>Just add <code>.options</code> to your second <code>for</code> block like you have above:</p>
  
  <pre><code>{% for checkboxOption in entry.gistCategories.options %}
  </code></pre>
  
  <p>That'll loop through all of 'em, checked or not.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-17T20:56:17.500Z
Answers.LastActivityDate: 2015-02-17T20:56:17.500Z
Answers.UserDisplayName: RitterKnight
Body: <p>I have tried to follow the instructions listed <a href="http://buildwithcraft.com/docs/checkboxes-fields" rel="nofollow noreferrer">here for checkboxes on frontend forms</a> but have not been successful in implementation.</p>
  
  <p>First, here is my code:</p>
  
  <pre><code>&lt;form method="post" action="" accept-charset="UTF-8" enctype="multipart/form-data"&gt;
  &lt;div class="form-group"&gt;
  &lt;h3&gt;Push to GistServers for Gist {{ entry.id }}&lt;/h3&gt;
  &lt;input type="hidden" name="action" value="gistClient/pushGistUnits"&gt;
  &lt;input type="hidden" name="entryId" value="{{ entry.id }}"&gt;
  &lt;p&gt;Select Gist Categories for Distribution.&lt;/p&gt;
  {% if entry.gistCategories | length == 0 %}
      &lt;ul&gt;
          {% for option in entry.gistCategories.options %}
          &lt;input type="checkbox" value="{{ option.value }}" name="fields[gistCategories][]"&gt; {{ option.label }}&lt;br&gt;
          {% endfor %}
      &lt;/ul&gt;
  {% else %}    
      &lt;ul&gt;
      {% for checkboxOption in entry.gistCategories %}
          {% set checked = false %}
  
          {% if checkboxOption.selected %}
              {% set checked = true %}
  
          {% endif %}
  
          {% if not checked %}
              &lt;input type="checkbox" value="{{ checkboxOption.value }}" name="fields[gistCategories][]" {% if checked %} checked="checked"{% endif %}&gt;{{ checkboxOption.label }}&lt;br&gt;
          {% endif %}
  
          &lt;input type="checkbox" value="{{ checkboxOption.value }}" name="fields[gistCategories][]" {% if checked %} checked="checked"{% endif %}&gt;{{ checkboxOption.label }}&lt;br&gt;
      {% endfor %}
      &lt;/ul&gt;
  {%endif%}
  
  {{ getCsrfInput() }}
  {% if entry.socialPush == true %}
      {% set socialPush = "Push to GistServers"%}
      {% set socialPushBtn = "default"%}
  {% else %}
      {% set socialPush = "Push to GistServers"%}
      {% set socialPushBtn = "success"%}
  {% endif %}
  
  &lt;button class="btn btn-{{socialPushBtn}}  btn-sm btn " style="margin:10px 15px 0 0;" type="submit" name="fields[gistDraft]" value="0"&gt;{{ socialPush }}&lt;/button&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <p></p>
  
  <p>Now for screen caps showing behavior. </p>
  
  <p>Before form submit</p>
  
  <p><img src="https://i.sstatic.net/vaylr.png" alt="enter image description here"></p>
  
  <p>CP View after form submit</p>
  
  <p><img src="https://i.sstatic.net/vpFIq.png" alt="enter image description here"></p>
  
  <p>Frontend form after submit.</p>
  
  <p><img src="https://i.sstatic.net/XC7I6.png" alt="enter image description here"></p>
  
  <p>Ideally, After I submit the frontend form my users would be able to see all checkboxes again in case they need to change the selections. I am at a loss and would appreciate some rescue here.</p>
  
Tags: <frontend><checkboxes>
Title: Getting Checkboxes to work on Frontend Forms
ThreadText: # Getting Checkboxes to work on Frontend Forms
  
  (Asked by: username_0 on 2015-02-17)
  
  I have tried to follow the instructions listed [here for checkboxes on frontend forms](http://buildwithcraft.com/docs/checkboxes-fields) but have not been successful in implementation.
  
  First, here is my code:
  
  ```
  <form method="post" action="" accept-charset="UTF-8" enctype="multipart/form-data">
  <div class="form-group">
  <h3>Push to GistServers for Gist {{ entry.id }}</h3>
  <input type="hidden" name="action" value="gistClient/pushGistUnits">
  <input type="hidden" name="entryId" value="{{ entry.id }}">
  <p>Select Gist Categories for Distribution.</p>
  {% if entry.gistCategories | length == 0 %}
      <ul>
          {% for option in entry.gistCategories.options %}
          <input type="checkbox" value="{{ option.value }}" name="fields[gistCategories][]"> {{ option.label }}<br>
          {% endfor %}
      </ul>
  {% else %}    
      <ul>
      {% for checkboxOption in entry.gistCategories %}
          {% set checked = false %}
  
          {% if checkboxOption.selected %}
              {% set checked = true %}
  
          {% endif %}
  
          {% if not checked %}
              <input type="checkbox" value="{{ checkboxOption.value }}" name="fields[gistCategories][]" {% if checked %} checked="checked"{% endif %}>{{ checkboxOption.label }}<br>
          {% endif %}
  
          <input type="checkbox" value="{{ checkboxOption.value }}" name="fields[gistCategories][]" {% if checked %} checked="checked"{% endif %}>{{ checkboxOption.label }}<br>
      {% endfor %}
      </ul>
  {%endif%}
  
  {{ getCsrfInput() }}
  {% if entry.socialPush == true %}
      {% set socialPush = "Push to GistServers"%}
      {% set socialPushBtn = "default"%}
  {% else %}
      {% set socialPush = "Push to GistServers"%}
      {% set socialPushBtn = "success"%}
  {% endif %}
  
  <button class="btn btn-{{socialPushBtn}}  btn-sm btn " style="margin:10px 15px 0 0;" type="submit" name="fields[gistDraft]" value="0">{{ socialPush }}</button>
  </div> 
  
  ```
  
  Now for screen caps showing behavior.
  
  Before form submit
  
  ![enter image description here](https://i.sstatic.net/vaylr.png)
  
  CP View after form submit
  
  ![enter image description here](https://i.sstatic.net/vpFIq.png)
  
  Frontend form after submit.
  
  ![enter image description here](https://i.sstatic.net/XC7I6.png)
  
  Ideally, After I submit the frontend form my users would be able to see all checkboxes again in case they need to change the selections. I am at a loss and would appreciate some rescue here.
  
  **Tags:** frontend, checkboxes
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-02-17. Score: 3 | Accepted answer
  
  The first loop you're using loops over `entry.gistCategories.options`, which contains all the options available. However, in the second loop (when `entry.gistCategories|length !== 0`), you're only looping over the options that have been selected.
  
  Try this:
  
  ```
  {% if entry.gistCategories | length == 0 %}
      <ul>
          {% for option in entry.gistCategories.options %}
              {# output checkboxes #}
          {% endfor %}
      </ul>
  {% else %}  
      <ul>
          {% for checkboxOption in entry.gistCategories.options %}
              {# output checkboxes #}
          {% endfor %}
      </ul>
  {% endif %}
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2015-02-17. Score: 2
  
  Since the form was already submitted, your code is only looping through the checkboxes that were checked.
  
  Just add `.options` to your second `for` block like you have above:
  
  ```
  {% for checkboxOption in entry.gistCategories.options %}
  
  ```
  
  That'll loop through all of 'em, checked or not.
  
  
  ---
  
  