<p>You can't just append rows to an existing table field from a form. The  controller expects the complete data set, so you'd need to query for the existing rows in your template and post them together with the new rows for that field.</p>

CC BY-SA 3.0
2016-03-18T09:26:27.243Z
Thanks @carlcs, that makes sense. But this solution (or method I'm using to store data) doesn't feel right if to add 1 row, it has to re-submit the whole table which could be hundreds of rows.

Or do you think this is OK? Or should I find another method?
Rich Holt
CC BY-SA 3.0
2016-03-18T09:34:43.143Z
I could create a table for every tutorial, so the table just stores the checkbox value. But this would be painful
Rich Holt
CC BY-SA 3.0
2016-03-17T23:51:29.240Z
2016-03-17T23:51:29.240Z
carlcs
<p>A tricky one.</p>

<p>I have a form which sits on a section entry template. When user submits form from one page of the template, it saves the entries into the table. </p>

<p>BUT user going to another page of the template (where user can see same form), the table doesn't keep the previously stored instruction ID rows. See first column, only saving from most recent form submit. </p>

<p>Ultimately I'm just trying to store the checkbox value (1 inside each matrix block). In table, if block.id exists (in 'instruction' column), then overwrite checkbox value, otherwise add new row.</p>

<p><a href="https://i.sstatic.net/N4Xi6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/N4Xi6.png" alt="enter image description here"></a></p>

<p>How the tutorial template is set up:</p>

<blockquote>
  <p>template for tutorial </p>
  
  <blockquote>
    <p>form which wraps around the matrix blocks</p>
    
    <blockquote>
      <p>matrix block contains form input checkbox </p>
      
      <blockquote>
        <p>submit sends form data to entry of user in another Section (see below)</p>
      </blockquote>
    </blockquote>
  </blockquote>
</blockquote>

<p>The makeshift "database" Section to store values:</p>

<blockquote>
  <p>Section </p>
  
  <blockquote>
    <p>Entry per user</p>
    
    <blockquote>
      <p>Inside Entry I have a table (multiple per tutorial parent)</p>
      
      <blockquote>
        <p>"instruction" column holds the block.id and "done" holds value of checkbox.</p>
      </blockquote>
    </blockquote>
  </blockquote>
</blockquote>

<p><a href="https://i.sstatic.net/I1FD2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/I1FD2.png" alt="enter image description here"></a></p>

<p>In the crazy if/for logic around the checkbox input, I had to do this to get it to work, where if a table had rows, it wasn't showing checkboxes on other tutorials, etc, etc. </p>

<pre><code>    {% set progressBob = craft.entries.section('userProgress').authorId(currentUser.id).find() %}

    &lt;form method="post" accept-charset="UTF-8"&gt;
      {{ getCsrfInput() }}
      &lt;input type="hidden" name="action" value="entries/saveEntry"&gt;
      &lt;input type="hidden" name="redirect" value=""&gt;
      &lt;input type="hidden" name="sectionId" value="6"&gt;
      &lt;input type="hidden" name="enabled" value="1"&gt;

      {% macro errorList(errors) %}
          {% if errors %}
              &lt;ul class="errors"&gt;
                  {% for error in errors %}
                      &lt;li&gt;{{ error }}&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
          {% endif %}
      {% endmacro %}

      {% from _self import errorList %}

      {% for entry in progressBob %}
        {% set tableentry = entry %}
        &lt;input type="hidden" name="entryId" value="{{ tableentry.id }}"&gt;
      {% endfor %}

      {% for block in entry.tutorialMatrix %}
        {% if block.type == "instruction" %}

            {% set tableProgress = product.slug|trim('kit') ~ 'Progress' %}

            &lt;input type="hidden" id="instruction{{ block.id }}" name="fields[{{ tableProgress }}][{{ block.id }}][col1]" value="{{ block.id }}" /&gt;

            &lt;div class="instruction m-b-3 m-l-3"&gt;
              &lt;label class="checkbox"&gt;

              {% if progressBob %} 

                {% for entry in progressBob %}
                  {% set tableentry = entry %}
                  {% if tableentry[tableProgress] %}

                      {% for row in tableentry[tableProgress] %} 

                          {% if row.instruction == block.id %}
                            &lt;input type="hidden" id="done{{ block.id }}" value="" name="fields[{{ tableProgress }}][{{ block.id }}][col2]" class="option-input checkbox" /&gt;
                            &lt;input type="checkbox" id="done{{ block.id }}" value="1" name="fields[{{ tableProgress }}][{{ block.id }}][col2]" {% if row.done %} checked="checked"{% endif %} class="option-input checkbox" /&gt;
                          {% endif %}

                      {% endfor %}

                  {% else %}
                    &lt;input type="hidden" id="done{{ block.id }}" value="" name="fields[{{ tableProgress }}][{{ block.id }}][col2]" class="option-input checkbox" /&gt;
                    &lt;input type="checkbox" id="done{{ block.id }}" value="1" name="fields[{{ tableProgress }}][{{ block.id }}][col2]" {% if row.done %} checked="checked"{% endif %} class="option-input checkbox" /&gt;
                  {% endif %}
                {% endfor %}

              {% else %} 
                &lt;input type="hidden" id="done{{ block.id }}" value="" name="fields[{{ tableProgress }}][{{ block.id }}][col2]" class="option-input checkbox" /&gt;
                &lt;input type="checkbox" id="done{{ block.id }}" value="1" name="fields[{{ tableProgress }}][{{ block.id }}][col2]" {% if row.done %} checked="checked"{% endif %} class="option-input checkbox" /&gt;
              {% endif %}

              &lt;span class="instructionLabel"&gt;{{ block.text }}&lt;/span&gt;
              &lt;pre class="prettyprint linenums"&gt;{{ block.code }}&lt;/pre&gt;
              {% set image = block.image.first() %}
              {% if image %}
                &lt;img src="{{ image.getUrl() }}" class="content-image" alt="{{ image.title }}"&gt;
              {% endif %}
              &lt;/label&gt;
            &lt;/div&gt;  

        {% endif %}
      {% endfor %}

      &lt;input type="submit" value="Publish" class="btn btn-primary"&gt;

    &lt;/form&gt;
</code></pre>

<p>Any help is much appreciated</p>

<matrix><form><table-field><saveentry>
<form><matrixBlock><checkbox></matrixBlock></form> How do I store multiple form entries in 1 table field?
# <form><matrixBlock><checkbox></matrixBlock></form> How do I store multiple form entries in 1 table field?

(Asked by: username_0 on 2016-03-16)

A tricky one.
I have a form which sits on a section entry template. When user submits form from one page of the template, it saves the entries into the table. 
BUT user going to another page of the template (where user can see same form), the table doesn't keep the previously stored instruction ID rows. See first column, only saving from most recent form submit. 
Ultimately I'm just trying to store the checkbox value (1 inside each matrix block). In table, if block.id exists (in 'instruction' column), then overwrite checkbox value, otherwise add new row.

How the tutorial template is set up:

template for tutorial 

form which wraps around the matrix blocks

matrix block contains form input checkbox 

submit sends form data to entry of user in another Section (see below)




The makeshift "database" Section to store values:

Section 

Entry per user

Inside Entry I have a table (multiple per tutorial parent)

"instruction" column holds the block.id and "done" holds value of checkbox.





In the crazy if/for logic around the checkbox input, I had to do this to get it to work, where if a table had rows, it wasn't showing checkboxes on other tutorials, etc, etc. 
    {% set progressBob = craft.entries.section('userProgress').authorId(currentUser.id).find() %}

    
      {{ getCsrfInput() }}
      
      
      
      

      {% macro errorList(errors) %}
          {% if errors %}
              
                  {% for error in errors %}
                      {{ error }}
                  {% endfor %}
              
          {% endif %}
      {% endmacro %}

      {% from _self import errorList %}

      {% for entry in progressBob %}
        {% set tableentry = entry %}
        
      {% endfor %}

      {% for block in entry.tutorialMatrix %}
        {% if block.type == "instruction" %}

            {% set tableProgress = product.slug|trim('kit') ~ 'Progress' %}

            

            
              

              {% if progressBob %} 

                {% for entry in progressBob %}
                  {% set tableentry = entry %}
                  {% if tableentry[tableProgress] %}

                      {% for row in tableentry[tableProgress] %} 

                          {% if row.instruction == block.id %}
                            
                            
                          {% endif %}

                      {% endfor %}

                  {% else %}
                    
                    
                  {% endif %}
                {% endfor %}

              {% else %} 
                
                
              {% endif %}

              {{ block.text }}
              {{ block.code }}
              {% set image = block.image.first() %}
              {% if image %}
                
              {% endif %}
              
              

        {% endif %}
      {% endfor %}

      

    

Any help is much appreciated

**Tags:** matrix, form, table-field, saveentry

---

## 1 answers

### Answer by username_1 on 2016-03-17. Score: 2 | Accepted answer

You can't just append rows to an existing table field from a form. The controller expects the complete data set, so you'd need to query for the existing rows in your template and post them together with the new rows for that field.

> **Comments:**
> **username_0**: Thanks @carlcs, that makes sense. But this solution (or method I'm using to store data) doesn't feel right if to add 1 row, it has to re-submit the whole table which could be hundreds of rows.  Or do you think this is OK? Or should I find another method?  
> **username_0**: I could create a table for every tutorial, so the table just stores the checkbox value. But this would be painful  

---

