Conditional file attachments

The file field is a supported conditional field. But apart from simply showing/hiding groups based on the fact if a file is selected or not, you can also add files conditionally.

Attach files from your media library conditionally

Take this form as an example:

Select file: [select "file-1" "file-2" "file-3"]
[group g1]file-1 will be emailed to you[/group]
[group g2]file-2 will be emailed to you[/group]
[group g3]file-3 will be emailed to you[/group]
[submit]

Now in the Mail tab, in the “File attachments” field enter this:

[g1]
uploads/2019/07/file-1.pdf
[/g1]
[g2]
uploads/2019/07/file-2.pdf
[/g2]
[g3]
uploads/2019/07/file-3.pdf
[/g3]

Note that, to add files from your library, you need to get the absolute path. i.e.: https://example.com/wp-content/uploads/2019/07/file-1.pdf, and only keep the part after https://example.com/wp-content/. So in this case the part you keep would be: uploads/2019/07/file-1.pdf

For security reasons, you are not allowed to add full URLs as file attachments. See CF7 documentation.

Form

Select files:

file-1 will be emailed to you
file-2 will be emailed to you
file-3 will be emailed to you

Form Code

Select files: [select menu-1 multiple "file-1" "file-2" "file-3"]
[group g1]file-1 will be emailed to you[/group]
[group g2]file-2 will be emailed to you[/group]
[group g3]file-3 will be emailed to you[/group]
[submit]

Conditional Fields (export)

show [g1] if [menu-1] equals "file-1"
show [g2] if [menu-1] equals "file-2"
show [g3] if [menu-1] equals "file-3"

Attach user uploaded files

In most cases you would not need conditional logic to handle files uploaded by the user. But I’ll add an example for completeness.

The form:

File 1: [file file-1]
File 2: [file file-2]
File 3: [file file-3]
[submit]

In the “File attachments” field add this:

[file-1]
[file-2]
[file-3]

Only non-empty file fields will be added to attachments, so no need to specify conditions in this case. This is the default CF7 behavior.