Hiding Data with Liquid

I have the following listed in a ‘thank you’ page when you submit a form -

 <table class="system_table" cellpadding="0" cellspacing="0">
{% assign allFields = formSubmissionData.fields.all %}
{% for item in allFields %} {% assign index = forloop.index -1 %}
{% assign fieldName = allFields[index].name %}
{% assign fieldValue = allFields[index].value %}
<tr>
  <td> {{fieldName}} </td>
  <td> {{fieldValue}} </td>
</tr>
{% endfor %}

There are two fields that I don’t want included though. Is there anyway of hiding these as they will always come through blank without any data so we don’t want it displaying in the results.

Hi @SiroccoDigital

You can add an UNLESS statement (which is kinda just the reverse of an IF statement) inside your forloop that checks for the 2 fields:

<table class="system_table" cellpadding="0" cellspacing="0">
{% assign allFields = formSubmissionData.fields.all %}
{% for item in allFields %} {% assign index = forloop.index -1 %}
{% assign fieldName = allFields[index].name %}
{% assign fieldValue = allFields[index].value %}

{% unless fieldName == 'FIELD NAME 1' or fieldName == 'FIELD NAME 2' %}

<tr>
  <td> {{fieldName}} </td>
  <td> {{fieldValue}} </td>
</tr>

{% endunless %}

{% endfor %}

@SiroccoDigital Another way would be not to use formSubmissionData.fields.all and loop through it, but to use formSubmissionData.fields.custom.[field].value and then pick just those fields you would like to see on your Thankyou page.

@Adam.Wilson I have tried using this with the fields setup in both ‘{{formSubmissionData.fields.custom.ProductAssemblyRequired.value}}’ and ‘{{this.formSubmissionData.fields.custom.ProductAssemblyRequired.value}}’ and it doesn’t want to remove these fields from the data list.

Hi @SiroccoDigital. What does your unless statement line look like? Can you post it here?

It is -

{% unless fieldName == ‘{{formSubmissionData.Fields.custom.ProductAssemblyRequired.value}}’ or fieldName == ‘{{formSubmissionData.Fields.custom.InstallationRequired.value}}’ %}

{{fieldName}} {{fieldValue}} {% endunless %}

Ok, so the values here actually need to be the hard coded field names, ie:

{% unless fieldName == 'Product Assembly Required' or fieldName == 'Installation Required' %}
...

@Adam.Wilson you have totally nailed it again! Thank you.

1 Like