0

I'm using this basic code to output form results:

{exp:freeform:entries form_name="{segment_3}"}
 {freeform:all_form_fields}
  <p>
   <label>{freeform:field_label}:</label>
   {freeform:field_output}
  </p>
 {/freeform:all_form_fields}
{/exp:freeform:entries} 

It works great for all of my forms, except for when I encounter a File Upload field: it just outputs the filename (without a link to the file). Is there a better way write this code for possible File fields?

1

Yes, there is.

When looping through your {freeform:all_form_fields} you will need to test the {freeform:field_output} and alter the html markup you dump your field data into.

IE:

{exp:freeform:entries form_name="{segment_3}"}
    {freeform:all_form_fields}
    <p>
        <label>{freeform:field_label}</label>
        {if freeform:field_type == 'text'}
            {freeform:field_output}
        {/if}
        {if freeform:field_type == 'file'}
            <img src="{freeform:field_output}">
        {/if}
    </p>
    {/freeform:all_form_fields}
{/exp:freeform:entries} 

Not sure if the field_type is actually named file for a file upload you will need to find out.

Here is the documentation area of freeform i pulled this syntax from.

http://www.solspace.com/docs/freeform/entries/#variable_pairs

0
0

Thanks, mattidjohn. I just had to change field_type to "file_upload" and manually type in the URL to the file, since field_output only produces a filename. Since you can choose Upload Destination per File Upload field, I don't exactly like hard-coding it to one upload location, but I don't see any variable to reference to find the Upload Destination. (If so, that would make the code scalable and better.)

{if freeform:field_type == 'file_upload'}
  <a href="{site_url}docs/{freeform:field_output}">{freeform:field_output}</a>
{/if}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.