Answers.Body: <p>I think this might be related to form-data rather than being an actual Craft-issue.</p>
  
  <p>Basically - when you submit your form, the data gets passed to the server. If we have checkboxes A, B and C with names checkboxes[] - and we check them all, the server would receive a <code>checkboxes</code> array looking like this:</p>
  
  <pre><code>['A', 'B', 'C']
  </code></pre>
  
  <p>However, if you check none of them and submit, the <code>checkboxes</code> array would look like this:</p>
  
  <pre><code>[]
  </code></pre>
  
  <p>So basically - in order to "uncheck" previously checked boxes in saved data, you have to implement your own "unchecking" routine.</p>
  
  <p>Mocking it up really quickly:</p>
  
  <pre><code>foreach savedData.checkboxes as i =&gt; checkbox
      savedData.checkboxes[i] = in_array(checkbox, checkboxes)
  endforeach
  </code></pre>
  
  <p>Basically you loop through all checkboxes in the savedData, and set it to checked if it also exists in the <code>checkboxes</code> array; otherwise you set it to "unchecked"</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-13T12:58:03.997Z
Answers.Text: @fuglesetrampen I'm not following what I should do. Is this javascript? or twig?
Answers.UserDisplayName: CreateSean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-13T13:32:21.883Z
Answers.Text: It's neither, I just mocked it up without using a language at all
  
  Basically, what you would have to do, is have a plugin receive the formData (I dunno if you have this already?) and in that plugin handle checking (pun not intended) if your checkboxes are checked or not, and set the data on the EntryModel (I'm assuming) that you're about to save.
Answers.UserDisplayName: Fuglsetrampen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-13T13:34:37.633Z
Answers.Text: Or - I suppose you could handle it through JavaScript if you're more familiar with that.
  
  You would have to do roughly the same thing (which is what the form isn't doing) is create an array of the checkboxes where you specify that one or more of them aren't checked, and pass that into whatever action your form is set to use. Basically the form only says which boxes are checked, the un-checked one are completely disregarded.
Answers.UserDisplayName: Fuglsetrampen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-13T10:25:04.203Z
Answers.LastActivityDate: 2017-10-13T10:25:04.203Z
Answers.UserDisplayName: Fuglsetrampen
Answers.Body: <p>Your code is correct but you need to add another line near the top:</p>
  
  <pre><code> &lt;input type="hidden" name="fields[volunteerPositions]" value=""&gt;
  </code></pre>
  
  <p>From the <a href="https://craftcms.com/docs/checkboxes-fields#templating" rel="noreferrer">documentation</a>:</p>
  
  <blockquote>
    <p>If you are including a Checkboxes field on a front-end entry from, make sure to include a hidden input before the checkboxes, so that an empty value is submitted if no checkboxes are checked.</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-13T19:16:10.037Z
Answers.Text: N/P: this has tripped me up before too!
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-13T15:08:37.267Z
Answers.LastActivityDate: 2017-10-13T15:08:37.267Z
Answers.UserDisplayName: RitterKnight
Body: <p>I have a frontend entry form with some checkboxes that is not behaving correctly.</p>
  
  <p>If you uncheck all options and save, nothing changes (this is bad). However if you uncheck one item and check another item it saves correctly.</p>
  
  <p>Additionally in the Craft CP if you uncheck all items it saves correctly so it clearly works there. </p>
  
  <p>relevant template code:</p>
  
  <pre><code>{% for volunteer in craft.entries.section('careers').search('positionType:volunteerPosition') %}
    &lt;label class="d-block"&gt; 
          &lt;input type="checkbox" class="form-check-input" name="fields[volunteerPositions][]" class="form-check-input" value="{{volunteer.id}}" {% if volunteer.id in selectedEntries %}checked{% endif %}&gt;&amp;nbsp;&amp;nbsp;{{volunteer.title}}  (created by {{volunteer.author }}) 
        &lt;/label&gt; 
  {% endfor %}
  </code></pre>
  
  <p>Please advise.</p>
  
Tags: <frontend><checkboxes><frontend-form>
Title: Frontend Form - Checkboxes cannot "all" be unchecked
ThreadText: # Frontend Form - Checkboxes cannot "all" be unchecked
  
  (Asked by: username_0 on 2017-10-12)
  
  I have a frontend entry form with some checkboxes that is not behaving correctly.
  
  If you uncheck all options and save, nothing changes (this is bad). However if you uncheck one item and check another item it saves correctly.
  
  Additionally in the Craft CP if you uncheck all items it saves correctly so it clearly works there.
  
  relevant template code:
  
  ```
  {% for volunteer in craft.entries.section('careers').search('positionType:volunteerPosition') %}
    <label class="d-block"> 
          <input type="checkbox" class="form-check-input" name="fields[volunteerPositions][]" class="form-check-input" value="{{volunteer.id}}" {% if volunteer.id in selectedEntries %}checked{% endif %}>&nbsp;&nbsp;{{volunteer.title}}  (created by {{volunteer.author }}) 
        </label> 
  {% endfor %}
  
  ```
  
  Please advise.
  
  **Tags:** frontend, checkboxes, frontend-form
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-10-13. Score: 6 | Accepted answer
  
  Your code is correct but you need to add another line near the top:
  
  ```
   <input type="hidden" name="fields[volunteerPositions]" value="">
  
  ```
  
  From the [documentation](https://craftcms.com/docs/checkboxes-fields#templating):
  
  > If you are including a Checkboxes field on a front-end entry from, make sure to include a hidden input before the checkboxes, so that an empty value is submitted if no checkboxes are checked.
  
  > **Comments:**
  > **username_2**: N/P: this has tripped me up before too!  
  
  ---
  
  ### Answer by username_1 on 2017-10-13. Score: 0
  
  I think this might be related to form-data rather than being an actual Craft-issue.
  
  Basically - when you submit your form, the data gets passed to the server. If we have checkboxes A, B and C with names checkboxes[] - and we check them all, the server would receive a `checkboxes` array looking like this:
  
  ```
  ['A', 'B', 'C']
  
  ```
  
  However, if you check none of them and submit, the `checkboxes` array would look like this:
  
  ```
  []
  
  ```
  
  So basically - in order to "uncheck" previously checked boxes in saved data, you have to implement your own "unchecking" routine.
  
  Mocking it up really quickly:
  
  ```
  foreach savedData.checkboxes as i => checkbox
      savedData.checkboxes[i] = in_array(checkbox, checkboxes)
  endforeach
  
  ```
  
  Basically you loop through all checkboxes in the savedData, and set it to checked if it also exists in the `checkboxes` array; otherwise you set it to "unchecked"
  
  > **Comments:**
  > **username_0**: @fuglesetrampen I'm not following what I should do. Is this javascript? or twig?  
  > **username_1**: It's neither, I just mocked it up without using a language at all  Basically, what you would have to do, is have a plugin receive the formData (I dunno if you have this already?) and in that plugin handle checking (pun not intended) if your checkboxes are checked or not, and set the data on the EntryModel (I'm assuming) that you're about to save.  
  > **username_1**: Or - I suppose you could handle it through JavaScript if you're more familiar with that.  You would have to do roughly the same thing (which is what the form isn't doing) is create an array of the checkboxes where you specify that one or more of them aren't checked, and pass that into whatever action your form is set to use. Basically the form only says which boxes are checked, the un-checked one are completely disregarded.  
  
  ---
  
  