Answers.Body: <p>First, when you do this:</p>
  
  <pre><code>{% for row in currentUser.providerPayment %}
  
      ...
  
      {% for slidingScale in currentUser.providerPayment %}
  </code></pre>
  
  <p>you’re looping through the <code>currentUser.providerPayment</code> array (the rows in your providerPayment Table field on the current user) within another loop through the same array. If the table has 2 rows, this is what would be happening:</p>
  
  <ul>
  <li>Row 1 (assigned to <code>row</code>)
  <ul>
  <li>Row 1 (assigned to <code>slidingScale</code>)</li>
  <li>Row 2 (assigned to <code>slidingScale</code>)</li>
  </ul></li>
  <li>Row 2 (assigned to <code>row</code>)
  <ul>
  <li>Row 1 (assigned to <code>slidingScale</code>)</li>
  <li>Row 2 (assigned to <code>slidingScale</code>)</li>
  </ul></li>
  </ul>
  
  <p>(Doesn’t make any sense.)</p>
  
  <p>You only need a single for-loop here, and it’s the outer one. Within that loop, you will be able to access all of the values on the current row, via the <code>row</code> variable you’ve defined:</p>
  
  <pre><code>{% for row in currentUser.providerPayment %}
  
      {{ row.averageCostPerSession }}
      {{ row.slidingScale }}
      {{ row.acceptedPaymentMethods }}
      {{ row.acceptedInsuranceCarriers }}
  
  {% endfor %}
  </code></pre>
  
  <p>Does that make sense?</p>
  
  <p>So, for each row, if you want to output a checkbox input, you would just do this:</p>
  
  <pre><code>{% for row in currentUser.providerPayment %}
      &lt;td&gt;
          &lt;input type="checkbox" value="1"
              name="fields[providerPayment][0][col2]"
              {% if row.sliderScale %} checked="checked"{% endif %}&gt;
      &lt;/td&gt;
  {% endfor %}
  </code></pre>
  
  <p>One thing to keep in mind with checkboxes, though, is that they don’t actually submit any POST data if left unchecked. So to be safe, you should put a hidden input right before the checkbox input, with a blank value, which will act as the default value if the checkbox is left unchecked:</p>
  
  <pre><code>{% set name = 'fields[providerPayment][0][col2]' %}
  
  {% for row in currentUser.providerPayment %}
      &lt;td&gt;
          &lt;input type="hidden" name="{{ name }}" value=""&gt;
          &lt;input type="checkbox" name="{{ name }}" value="1"
              {% if row.sliderScale %} checked="checked"{% endif %}&gt;
      &lt;/td&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-21T23:34:37.313Z
Answers.LastActivityDate: 2014-11-21T23:34:37.313Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>This is an extension of a question I posted <a href="https://craftcms.stackexchange.com/questions/4860/edit-a-table-field-type-from-the-front-end">here</a> earlier, but another layer of complexity.</p>
  
  <p>I'm trying to have a checkbox field <em>within</em> a table field be checked/unchecked from a front end form.</p>
  
  <p>I've tried a number of scenarios using the example found <a href="http://buildwithcraft.com/docs/checkboxes-fields#templating" rel="nofollow noreferrer">here</a> in the docs, but no dice.</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>    &lt;table&gt;
        {% for row in currentUser.providerPayment %}
      &lt;tr&gt;
          &lt;td&gt;Sliding scale?&lt;/td&gt;
  
          {% for slidingScale in currentUser.providerPayment  %}
              {% set checked = false %}
  
              {% if slidingScale.selected %}
                  {% set checked = true %}
              {% endif %}
  
              {% if not checked %}
                  &lt;input type="hidden" name="fields[providerPayment][0][col2]" value=""&gt;
              {% endif %}
  
              &lt;td&gt;&lt;input type="checkbox" value="{{ slidingScale.value }}" name="fields[providerPayment][0][col2]" {% if checked %} checked="checked"{% endif %}&gt;&lt;/td&gt;
          {% endfor %}
      {% endfor %}
     &lt;/table&gt;
  </code></pre>
  
  <p>And here is the error it's producing:</p>
  
  <p><img src="https://i.sstatic.net/IIA7A.png" alt="enter image description here"></p>
  
  <p><strong>Update</strong> Here are my table field settings:</p>
  
  <p><img src="https://i.sstatic.net/ZqezG.png" alt="enter image description here"></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-21T22:50:25.393Z
Comments.Text: Can you post a screenshot of your Table field’s settings?
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-21T22:55:47.613Z
Comments.Text: Updated with the table field settings
Comments.UserDisplayName: Matt Steele
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-21T23:00:48.370Z
Comments.Text: Not sure I’m following - there’s no checkbox column in there?
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-21T23:04:07.753Z
Comments.Text: Ah, I had the wrong screenshot attached. It's updated now.
Comments.UserDisplayName: Matt Steele
Tags: <templating><form>
Title: Edit a checkbox field within table field from the front end
ThreadText: # Edit a checkbox field within table field from the front end
  
  (Asked by: username_0 on 2014-11-21)
  
  This is an extension of a question I posted [here](https://craftcms.stackexchange.com/questions/4860/edit-a-table-field-type-from-the-front-end) earlier, but another layer of complexity.
  
  I'm trying to have a checkbox field *within* a table field be checked/unchecked from a front end form.
  
  I've tried a number of scenarios using the example found [here](http://buildwithcraft.com/docs/checkboxes-fields#templating) in the docs, but no dice.
  
  Here is my current code:
  
  ```
      <table>
        {% for row in currentUser.providerPayment %}
      <tr>
          <td>Sliding scale?</td>
  
          {% for slidingScale in currentUser.providerPayment  %}
              {% set checked = false %}
  
              {% if slidingScale.selected %}
                  {% set checked = true %}
              {% endif %}
  
              {% if not checked %}
                  <input type="hidden" name="fields[providerPayment][0][col2]" value="">
              {% endif %}
  
              <td><input type="checkbox" value="{{ slidingScale.value }}" name="fields[providerPayment][0][col2]" {% if checked %} checked="checked"{% endif %}></td>
          {% endfor %}
      {% endfor %}
     </table>
  
  ```
  
  And here is the error it's producing:
  
  ![enter image description here](https://i.sstatic.net/IIA7A.png)
  
  **Update** Here are my table field settings:
  
  ![enter image description here](https://i.sstatic.net/ZqezG.png)
  
  **Tags:** templating, form
  
  > **Comments:**
  > **username_1**: Can you post a screenshot of your Table field’s settings?  
  > **username_0**: Updated with the table field settings  
  > **username_1**: Not sure I’m following - there’s no checkbox column in there?  
  > **username_0**: Ah, I had the wrong screenshot attached. It's updated now.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-11-21. Score: 2 | Accepted answer
  
  First, when you do this:
  
  ```
  {% for row in currentUser.providerPayment %}
  
      ...
  
      {% for slidingScale in currentUser.providerPayment %}
  
  ```
  
  you’re looping through the `currentUser.providerPayment` array (the rows in your providerPayment Table field on the current user) within another loop through the same array. If the table has 2 rows, this is what would be happening:
  
  * Row 1 (assigned to `row`)
    + Row 1 (assigned to `slidingScale`)
    + Row 2 (assigned to `slidingScale`)
  * Row 2 (assigned to `row`)
    + Row 1 (assigned to `slidingScale`)
    + Row 2 (assigned to `slidingScale`)
  
  (Doesn’t make any sense.)
  
  You only need a single for-loop here, and it’s the outer one. Within that loop, you will be able to access all of the values on the current row, via the `row` variable you’ve defined:
  
  ```
  {% for row in currentUser.providerPayment %}
  
      {{ row.averageCostPerSession }}
      {{ row.slidingScale }}
      {{ row.acceptedPaymentMethods }}
      {{ row.acceptedInsuranceCarriers }}
  
  {% endfor %}
  
  ```
  
  Does that make sense?
  
  So, for each row, if you want to output a checkbox input, you would just do this:
  
  ```
  {% for row in currentUser.providerPayment %}
      <td>
          <input type="checkbox" value="1"
              name="fields[providerPayment][0][col2]"
              {% if row.sliderScale %} checked="checked"{% endif %}>
      </td>
  {% endfor %}
  
  ```
  
  One thing to keep in mind with checkboxes, though, is that they don’t actually submit any POST data if left unchecked. So to be safe, you should put a hidden input right before the checkbox input, with a blank value, which will act as the default value if the checkbox is left unchecked:
  
  ```
  {% set name = 'fields[providerPayment][0][col2]' %}
  
  {% for row in currentUser.providerPayment %}
      <td>
          <input type="hidden" name="{{ name }}" value="">
          <input type="checkbox" name="{{ name }}" value="1"
              {% if row.sliderScale %} checked="checked"{% endif %}>
      </td>
  {% endfor %}
  
  ```
  
  
  ---
  
  