Answers.Body: <p>I figured out a solution.  When I looked in the database I could see <code>{"col1":"","col2":""}</code> in the content even though the user didn't enter any content in the front end text form field.  I couldn't figure out how to prevent the form from sending a value even if the field was empty, therefore, I added a conditional to the template page which displays the images.</p>
  
  <p>My conditional filters out any table rows that has a value of <code>""</code>.</p>
  
  <pre><code>{% if row.col1 != "" %}
  </code></pre>
  
  <p>I also added a conditional so my divider graphic either doesn't show (if all rows are <code>""</code>) or just once if any of the rows have user submitted content.</p>
  
  <pre><code>{% if row.col1 != "" and loop.first %}
  </code></pre>
  
  <p><strong>Here's my new code to display images if they were submitted.:</strong> </p>
  
  <pre><code>{% if entry.logReviewer_feedbackStillImages %}
      {% for row in entry.logReviewer_feedbackStillImages %}
          {% if row.col1 != "" and loop.first %}
              &lt;div class="c-margin-b-40 "&gt;
                  &lt;div class="c-content-divider c-icon-bg c-bg-blue-3"&gt;
                      &lt;i class="icon-picture c-rounded c-bg-blue-3 c-font-white"&gt;&lt;/i&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          {% endif %}
      {% endfor %}
  
      &lt;div class="c-body"&gt;
          {% for row in entry.logReviewer_feedbackStillImages %}
              {% if row.col1 != "" %}
              &lt;div class="c-margin-b-80"&gt;
                  &lt;div class="cl-feedbackText c-center c-margin-b-30"&gt;{{ row.comment|ucfirst }}&lt;/div&gt;
                  &lt;div class="embed-responsive embed-responsive-4by3 c-center c-margin-b-50"&gt;
                      &lt;img class="embed-responsive-item" src="{{ row.droplrImageLink }}+"&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              {% endif %}
          {% endfor %}
      &lt;/div&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-24T21:12:42.390Z
Answers.LastActivityDate: 2016-09-24T21:12:42.390Z
Answers.UserDisplayName: Lori
Body: <p>I have a front end form which contains text fields that are connected to a Craft table field.  The issue I have is that if I do not fill out the text input fields on the front end it is still creating table rows in the Craft entry.  When I looked in the database, I can see that even though I'm not filling out the text input fields in the form, it is still submitting information. This is what is being submitted when the text input field not being filled out: <code>[{"col1":"","col2":""},{"col1":"","col2":""}]</code> My guess is that I have something incorrect in how I'm coding the text input field in the form.</p>
  
  <p><strong>My question:</strong> Is there a way to either prevent the table row from getting added if the text input field is empty on the front end form?  If not, is there a way that I can use code on the summary template page where the images would be displayed on the front end to filter out any table rows that have no content?</p>
  
  <p><strong>Here's a screenshot of the form input:</strong> </p>
  
  <p><a href="https://i.sstatic.net/nzrz3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nzrz3.png" alt="enter image description here"></a></p>
  
  <p><strong>Here's my input form code:</strong></p>
  
  <pre><code>&lt;label for="stillImages1" class="field-label"&gt;Still Image 1&lt;/label&gt;
      &lt;div class="section"&gt;
          &lt;div class="frm-row"&gt;
              &lt;label for="" class="field prepend-icon"&gt;
                  &lt;input type="url" name="fields[logReviewer_feedbackStillImages][0][col1]" class="gui-input" placeholder="Paste image 1 link"&gt;
                  &lt;span class="field-icon"&gt;&lt;i class="fa fa-image"&gt;&lt;/i&gt;&lt;/span&gt;  
              &lt;/label&gt;
          &lt;/div&gt;&lt;!-- end frm-row --&gt;
          &lt;br /&gt;
          &lt;div class="frm-row"&gt;
              &lt;label for="" class="field prepend-icon"&gt;
                  &lt;textarea class="gui-textarea" name="fields[logReviewer_feedbackStillImages][0][col2]" placeholder="Type image 1 comments"&gt;&lt;/textarea&gt;
                  &lt;span class="field-icon"&gt;&lt;i class="fa fa-comments"&gt;&lt;/i&gt;&lt;/span&gt;  
              &lt;/label&gt;
          &lt;/div&gt;&lt;!-- end frm-row --&gt;                                          
      &lt;/div&gt;&lt;!-- end section --&gt;
  &lt;/label&gt;
  
  &lt;label for="stillImages2" class="field-label"&gt;Still Image 2&lt;/label&gt;
      &lt;div class="section"&gt;
          &lt;div class="frm-row"&gt;
              &lt;label for="" class="field prepend-icon"&gt;
                  &lt;input type="url" name="fields[logReviewer_feedbackStillImages][1][col1]" class="gui-input" placeholder="Paste image 2 link"&gt;
                  &lt;span class="field-icon"&gt;&lt;i class="fa fa-image"&gt;&lt;/i&gt;&lt;/span&gt;  
              &lt;/label&gt;
          &lt;/div&gt;&lt;!-- end frm-row --&gt;
          &lt;br /&gt;
          &lt;div class="frm-row"&gt;
              &lt;label for="" class="field prepend-icon"&gt;
                  &lt;textarea class="gui-textarea" name="fields[logReviewer_feedbackStillImages][1][col2]" placeholder="Type image 2 comments"&gt;&lt;/textarea&gt;
                  &lt;span class="field-icon"&gt;&lt;i class="fa fa-comments"&gt;&lt;/i&gt;&lt;/span&gt;  
              &lt;/label&gt;
          &lt;/div&gt;&lt;!-- end frm-row --&gt;                                           
      &lt;/div&gt;&lt;!-- end section --&gt;
  &lt;/label&gt;
  </code></pre>
  
  <p><strong>Here's a screenshot of the table field in Craft.  Even if I don't actually enter text in the text fields in the form, 2 table rows are created in the entry as shown in this screenshot below.</strong></p>
  
  <p><a href="https://i.sstatic.net/1BJRO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1BJRO.png" alt="enter image description here"></a></p>
  
  <p><strong>Here's my code to display images if they were submitted.</strong></p>
  
  <pre><code>{% if entry.logReviewer_feedbackStillImages|length %}
  
      &lt;div class="c-margin-b-40 "&gt;
          &lt;div class="c-content-divider c-icon-bg c-bg-blue-3"&gt;
              &lt;i class="icon-picture c-rounded c-bg-blue-3 c-font-white"&gt;&lt;/i&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="c-body"&gt;
          {% for row in entry.logReviewer_feedbackStillImages %}
  
              &lt;div class="c-margin-b-80"&gt;
                  &lt;div class="cl-feedbackText c-center c-margin-b-30"&gt;{{ row.comment|ucfirst }}&lt;/div&gt;
                  &lt;div class="embed-responsive embed-responsive-4by3 c-center c-margin-b-50"&gt;
                      &lt;img class="embed-responsive-item" src="{{ row.droplrImageLink }}+"&gt;
                  &lt;/div&gt;
  
              &lt;/div&gt;
          {% endfor %}
      &lt;/div&gt;
  {% endif %}
  </code></pre>
  
Tags: <templating><form><table-field>
Title: How do I prevent empty table rows from being created when a front end form is submitted?
ThreadText: # How do I prevent empty table rows from being created when a front end form is submitted?
  
  (Asked by: username_0 on 2016-09-23)
  
  I have a front end form which contains text fields that are connected to a Craft table field. The issue I have is that if I do not fill out the text input fields on the front end it is still creating table rows in the Craft entry. When I looked in the database, I can see that even though I'm not filling out the text input fields in the form, it is still submitting information. This is what is being submitted when the text input field not being filled out: `[{"col1":"","col2":""},{"col1":"","col2":""}]` My guess is that I have something incorrect in how I'm coding the text input field in the form.
  
  **My question:** Is there a way to either prevent the table row from getting added if the text input field is empty on the front end form? If not, is there a way that I can use code on the summary template page where the images would be displayed on the front end to filter out any table rows that have no content?
  
  **Here's a screenshot of the form input:**
  
  [![enter image description here](https://i.sstatic.net/nzrz3.png)](https://i.sstatic.net/nzrz3.png)
  
  **Here's my input form code:**
  
  ```
  <label for="stillImages1" class="field-label">Still Image 1</label>
      <div class="section">
          <div class="frm-row">
              <label for="" class="field prepend-icon">
                  <input type="url" name="fields[logReviewer_feedbackStillImages][0][col1]" class="gui-input" placeholder="Paste image 1 link">
                  <span class="field-icon"><i class="fa fa-image"></i></span>  
              </label>
          </div><!-- end frm-row -->
          <br />
          <div class="frm-row">
              <label for="" class="field prepend-icon">
                  <textarea class="gui-textarea" name="fields[logReviewer_feedbackStillImages][0][col2]" placeholder="Type image 1 comments"></textarea>
                  <span class="field-icon"><i class="fa fa-comments"></i></span>  
              </label>
          </div><!-- end frm-row -->                                          
      </div><!-- end section -->
  </label>
  
  <label for="stillImages2" class="field-label">Still Image 2</label>
      <div class="section">
          <div class="frm-row">
              <label for="" class="field prepend-icon">
                  <input type="url" name="fields[logReviewer_feedbackStillImages][1][col1]" class="gui-input" placeholder="Paste image 2 link">
                  <span class="field-icon"><i class="fa fa-image"></i></span>  
              </label>
          </div><!-- end frm-row -->
          <br />
          <div class="frm-row">
              <label for="" class="field prepend-icon">
                  <textarea class="gui-textarea" name="fields[logReviewer_feedbackStillImages][1][col2]" placeholder="Type image 2 comments"></textarea>
                  <span class="field-icon"><i class="fa fa-comments"></i></span>  
              </label>
          </div><!-- end frm-row -->                                           
      </div><!-- end section -->
  </label>
  
  ```
  
  **Here's a screenshot of the table field in Craft. Even if I don't actually enter text in the text fields in the form, 2 table rows are created in the entry as shown in this screenshot below.**
  
  [![enter image description here](https://i.sstatic.net/1BJRO.png)](https://i.sstatic.net/1BJRO.png)
  
  **Here's my code to display images if they were submitted.**
  
  ```
  {% if entry.logReviewer_feedbackStillImages|length %}
  
      <div class="c-margin-b-40 ">
          <div class="c-content-divider c-icon-bg c-bg-blue-3">
              <i class="icon-picture c-rounded c-bg-blue-3 c-font-white"></i>
          </div>
      </div>
  
      <div class="c-body">
          {% for row in entry.logReviewer_feedbackStillImages %}
  
              <div class="c-margin-b-80">
                  <div class="cl-feedbackText c-center c-margin-b-30">{{ row.comment|ucfirst }}</div>
                  <div class="embed-responsive embed-responsive-4by3 c-center c-margin-b-50">
                      <img class="embed-responsive-item" src="{{ row.droplrImageLink }}+">
                  </div>
  
              </div>
          {% endfor %}
      </div>
  {% endif %}
  
  ```
  
  **Tags:** templating, form, table-field
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-09-24. Score: 3 | Accepted answer
  
  I figured out a solution. When I looked in the database I could see `{"col1":"","col2":""}` in the content even though the user didn't enter any content in the front end text form field. I couldn't figure out how to prevent the form from sending a value even if the field was empty, therefore, I added a conditional to the template page which displays the images.
  
  My conditional filters out any table rows that has a value of `""`.
  
  ```
  {% if row.col1 != "" %}
  
  ```
  
  I also added a conditional so my divider graphic either doesn't show (if all rows are `""`) or just once if any of the rows have user submitted content.
  
  ```
  {% if row.col1 != "" and loop.first %}
  
  ```
  
  **Here's my new code to display images if they were submitted.:**
  
  ```
  {% if entry.logReviewer_feedbackStillImages %}
      {% for row in entry.logReviewer_feedbackStillImages %}
          {% if row.col1 != "" and loop.first %}
              <div class="c-margin-b-40 ">
                  <div class="c-content-divider c-icon-bg c-bg-blue-3">
                      <i class="icon-picture c-rounded c-bg-blue-3 c-font-white"></i>
                  </div>
              </div>
          {% endif %}
      {% endfor %}
  
      <div class="c-body">
          {% for row in entry.logReviewer_feedbackStillImages %}
              {% if row.col1 != "" %}
              <div class="c-margin-b-80">
                  <div class="cl-feedbackText c-center c-margin-b-30">{{ row.comment|ucfirst }}</div>
                  <div class="embed-responsive embed-responsive-4by3 c-center c-margin-b-50">
                      <img class="embed-responsive-item" src="{{ row.droplrImageLink }}+">
                  </div>
              </div>
              {% endif %}
          {% endfor %}
      </div>
  {% endif %}
  
  ```
  
  
  ---
  
  