Conditional logic in mapping values

Gravity Forms
19 May, 2021 18:43:36
ramsu
Topics: 7
Messages: 13
Hi,
Is it possible to have conditional logic when mapping values, either for text fields, radio buttons, or images?

For a radio option, tick radio in template, if multiple form fields are 'yes', like: If {one:1}==Pass & {two:2}==Pass & {three:3}==Pass, then tick radio in template
e.g. the form might ask the user 5 yes/no questions, and we want logic in the PDF template so if ALL 5 answers are YES, then tick single YES in PDF, otherwise can tick single NO in PDF.

And for images example, the PDF template has 3 photo locations like: [location1] [location2] [location3].
And gravity form asks user to upload 3 different photos (not mandatory), as file1, file2, file3
So:
- If user uploads files 1, 2 & 3, put those into 3 photo locations in template: [file1] [file2] [file3]
- If user only uploads file 2 & 3, put those into locations 1 & 2 in template: [file2] [file3] [empty]
- If user only uploads file 3, put that into location 1: [file3] [empty] [empty]

Is that possible?
Thanks
19 May, 2021 23:58:56
E2Pdf
Support
Topics: 7
Messages: 3163
Hi,

Yes, it must be possible.

- For "Radio" buttons you must add "Action" which will change "Value" to "Option Value" if "All" conditions met. Keep in mind please that it must be same "Actions" and "Conditions" set for all radios inside one "group". Screenshot 1.

- For Files it will be a bit more complex "Actions" and "Conditions" and by default we will leave all "Values" empty to change it only if it will meet some needed conditions.

1st field: (screenshot 2)
---- 1st action: check if file 1 not empty then use file 1
---- 2nd action: check if file 1 empty then use file 2
---- 3rd action: check if file 1 and file 2 empty then use file 3

2nd field (screenshot 3)
---- 1st action: check if file 1 not empty then use file 2
---- 2nd action: check if file 1 or file 2 empty then use file 3
---- 3rd action: check if file 1 and file 2 empty then use empty value

3rd field (screenshot 4)
---- 3rd action: check if file 1 and file 2 not empty then use file 3

We remain at your service.
We would really appreciate your feedback at WordPress.org!
20 May, 2021 04:01:29
ramsu
Topics: 7
Messages: 13
Thanks for the details on the radio buttons, that will work.

But the files one might end up being too complex.

Let me elaborate some more.
In our PDF template, we have space for 6 photos, like in the attachment.

In our gravity form (over multiple pages) we ask the user various questions on each 'room' in a house, and if applicable the user uploads up to 3 photos (as 3 separate file inputs).
These questions with photo uploads are duplicated over multiple 'pages' in the form.

So the user could upload:
- Room 1: 0 photos
- Room 2: 2 photos (r2-photo1, r2-photo2)
- Room 3: 3 photos (r3-photo1, r3-photo2, r3-photo3)
In total = 5 photos

How can we then map those 5 uploaded photos, to the 6 photo 'areas' in the PDF (as shown in attachment).

I'm guessing the logic is going to get very complex, as we need to somehow check if each photo exists, and then put into order, and into the 6 areas.
e.g. for the 1st PDF photo area, something like:
IF r1-photo1, show img, Else IF r1-photo2, show img, Else IF r1-photo3, show img, Else IF r2-photo1, show... and so on........

If you can't think of way of doing this directly in e2pdf, do you think something like this would work instead:

1. Hook into the gravity form submission (e.g. gform_pre_submission)
2. When user submits form, use some PHP logic to check for existing room photos, and build up a list of those photos
3. Take list of photos, and copy photos into more manageable fields of photo1, photo2, photo3, photo4, photo5, photo6 (presume these would need to be setup in gravity forms as hidden/admin fields?)
4. Form submitted as normal (with admin photo fields added)
5. e2PDF can then more easy map 1 to 1 of the 'admin' photo fields to PDF

What do you think?
20 May, 2021 06:22:01
E2Pdf
Support
Topics: 7
Messages: 3163
Hi,

After seeing your possible solution we currently extended an idea and released some update to RC version 1.15.05 which has some improvements to help to solve the current issue without custom PHP filters.

You can apply update now by turning on updates from "e2pdf.com". Option can be enabled at "E2Pdf" -> "Settings" -> "Release Candidate Builds" (screenshot). After enabling this option you must be able to check for updates at "Dashboard" -> "Updates" and update plugin as usual to version 1.15.05.

It's recommended to turn off this option after update.

After update you can try to use such shortcodes to output images separated:

For 1st image:
[e2pdf-format-output explode_filter="array_filter,array_values" explode="," output="{0}"]{File:85},{File:86},{File:87},{File:88},{File:89}[/e2pdf-format-output]

For 2nd image:
[e2pdf-format-output explode_filter="array_filter,array_values" explode="," output="{1}"]{File:85},{File:86},{File:87},{File:88},{File:89}[/e2pdf-format-output]

For 3rd image:
[e2pdf-format-output explode_filter="array_filter,array_values" explode="," output="{2}"]{File:85},{File:86},{File:87},{File:88},{File:89}[/e2pdf-format-output]

And so on... Let us know please if solution will work for you. Thank you.

We remain at your service.
We would really appreciate your feedback at WordPress.org!
20 May, 2021 14:29:15
ramsu
Topics: 7
Messages: 13
Hi,
That update sounds like it could work.

Just to confirm, I would list all possible files in between the e2pdf-format-output tags (as a comma list), and the output value will define which file to grab?

In your first example (below), what would happen if {File:85} was empty, would it automatically show {File:86} instead? (e.g array entry 0)

[e2pdf-format-output explode_filter="array_filter,array_values" explode="," output="{0}"]{File:85},{File:86},{File:87},{File:88},{File:89}[/e2pdf-format-output]

Thanks
20 May, 2021 21:01:16
E2Pdf
Support
Topics: 7
Messages: 3163
Yes, you are correct, you need to list all possible files in between the e2pdf-format-output tag (as a comma list), and the output value will define which file to grab.

If {File:85} will be empty then it will output {File:86} due the 'explode_filter="array_filter,array_values"' as it will remove any empty values - this is what was added in 1.15.05 version.

We remain at your service.
We would really appreciate your feedback at WordPress.org!
30 June, 2021 03:54:09
ramsu
Topics: 7
Messages: 13
Hi,

We have been using this solution of the array values for images and this has been working well so far, thanks.

But further to this, is it possible to count the number of images that exist in the array, for the purposes of showing/hiding a page?

This is the code we're using for images: (e.g. display image 0 in array)
[e2pdf-format-output explode_filter="array_filter,array_values" explode="," output="{0}"]{:687},{:693},{:696},{:699}[/e2pdf-format-output]

If those images are split over 2 pages (2 on each page), can I have a page action that does something like:

if (array count {:687},{:693},{:696},{:699}) <= 2) action = hide page

Thanks
30 June, 2021 04:25:22
E2Pdf
Support
Topics: 7
Messages: 3163
Hi,

Unfortunately there is no "count" output yet. We will check if we can add it with future updates, however you must be able to just to check if for example 2nd image exists and hide page if shortcode renders in empty value as:

If:
[e2pdf-format-output explode_filter="array_filter,array_values" explode="," output="{2}"]{:687},{:693},{:696},{:699}[/e2pdf-format-output]
Condition: =
Value: (empty)

Screenshot attached.

We remain at your service.

We would really appreciate your feedback at WordPress.org!