<p>The following template code resolved this issue for me:</p>

<pre><code>{% for field in submission.fieldMetadata %}
     {% if field.type == "file" %}
        {% set assetIds = attribute(submission, field.handle).value %}
        {% if assetIds %}
           {% for assetId in assetIds %}
              {% set asset = craft.assets.id(assetId).one() %}
              {% if asset %}
                 {% if asset.kind == "image" %}
                    &lt;img src="{{ asset.url }}" /&gt;
                 {% else %}
                    &lt;a href="{{ asset.url }}"&gt;{{ asset.filename }}&lt;/a&gt;
                 {% endif %}
              {% endif %}
           {% endfor %}
        {% endif %}

     {% else %}
        {{ attribute(submission, field.handle) }}
     {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2018-05-31T14:22:34.540Z
2018-05-31T14:22:34.540Z
PhilR
<p>I'm attempting to query for all assets associated with a specific form submission like this, where 'submission' has been set based on a URL parameter:</p>

<pre><code>{% for field in submission.fieldMetadata %}
    {% if field.type == "file" %}
        {% set assetId = attribute(submission, field.handle) %}
        {% set assets = craft.assets.id(assetId).all() %}
           {% for asset in assets %}
                {% if asset %}
                    {% if asset.kind == "image" %}
                        &lt;img src='{{ asset.url }}'&gt;
                    {% endif %}
                {% endif %}
            {% endfor %}
    {% endif %}
{% endfor %}
</code></pre>

<p>The above code returns all site assets rather than just the assets associated with the submission. All other fields associated with the submission are returned correctly. Is this a bug or is my template incorrect?</p>

<plugin-freeform><solspace>
Solspace Freeform query for submission assets returns all site assets
# Solspace Freeform query for submission assets returns all site assets

(Asked by: username_0 on 2018-05-25)

I'm attempting to query for all assets associated with a specific form submission like this, where 'submission' has been set based on a URL parameter:
{% for field in submission.fieldMetadata %}
    {% if field.type == "file" %}
        {% set assetId = attribute(submission, field.handle) %}
        {% set assets = craft.assets.id(assetId).all() %}
           {% for asset in assets %}
                {% if asset %}
                    {% if asset.kind == "image" %}
                        
                    {% endif %}
                {% endif %}
            {% endfor %}
    {% endif %}
{% endfor %}

The above code returns all site assets rather than just the assets associated with the submission. All other fields associated with the submission are returned correctly. Is this a bug or is my template incorrect?

**Tags:** plugin-freeform, solspace

---

## 1 answers

### Answer by username_0 on 2018-05-31. Score: 1

The following template code resolved this issue for me:
{% for field in submission.fieldMetadata %}
     {% if field.type == "file" %}
        {% set assetIds = attribute(submission, field.handle).value %}
        {% if assetIds %}
           {% for assetId in assetIds %}
              {% set asset = craft.assets.id(assetId).one() %}
              {% if asset %}
                 {% if asset.kind == "image" %}
                    
                 {% else %}
                    {{ asset.filename }}
                 {% endif %}
              {% endif %}
           {% endfor %}
        {% endif %}

     {% else %}
        {{ attribute(submission, field.handle) }}
     {% endif %}
{% endfor %}


---

