Hello,

The site that I maintain uses Webform Conditionals to determine which fields are displayed on certain pages. Specifically, I use a hidden field with the value [current-page:title] to identify the page. The conditionals applied to the appropriate fields show or hide them (usually, all but one field is hidden as they are semi-product specific. See: https://hartfordrents.com/360-camera-rental - The field "360 Camera Model:" that is 2/3 of the way down the form is shown while all other product-specific fields are hidden.

I am now experimenting with Dialog boxes and they are working fine except for the page-specific conditionals described above. I understand why this is happening; it is due to the fact that the form is being called into the dialog box as it's own page...

IE: a href="/form/quick-quote-form"

So, since it is it's own page essentially, it doesn't see the parent page's H1 tag and hence cannot fire the conditional for the field it needs to be displayed. All fields with conditionals are simply hidden since the page title of the form itself does not match the set conditions.

I am wondering if there is a way to either reference the form (in the href) in a way where it is still a part of the parent page or, is there an accepted token to refer back to the page and use that Page Title to fire the conditionals?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ericroks created an issue. See original summary.

ericroks’s picture

Issue summary: View changes
jrockowitz’s picture

Status: Active » Needs review

We can't really hack at the [current-page:title] in the webform module. You might want to use the [webform_submission:node:title] token. The current node is passed to the dialogs.

ericroks’s picture

I replaced [current-page:title] with [webform_submission:node:title] and an error was returned:

"Value is using the following invalid tokens: [webform_submission:node:title].
2 errors have been found: ValueDefault value"

jrockowitz’s picture

Do you have the webform_node.module enabled?

Try using [webform_submission:source-entity:title]

You might have post an example webform and/or a screenshot.

ericroks’s picture

Webform_node.module was not enabled (leftover from past database issues). I enabled and tried both tokens that you recommended, neither gave me the desired result.

Please, give me a day to prepare some screenshots & a more descriptive message for you. Perhaps a clearer picture needs to be painted.

ericroks’s picture

FileSize
482.08 KB
528.42 KB
529.58 KB
601.55 KB
493.28 KB
579.52 KB
563.51 KB

As it stands now, I have a webform that is placed in a block that is used over all of our product pages called "Quick Quote Form". It uses conditional logic to hide/display the appropriate product fields on the individual product pages.
Only local images are allowed.

The form determines which page it is on by placing the token [current-page:title] in a hidden field called "Current Page". Basically, sniffing out the H1 tag on the page.
Only local images are allowed.

As you can see, there are lots of fields that are being toggled by this conditional. For this instance, we will be looking at "360 Camera Models".
Screen

On the conditions tab for 360 Camera Model, I use the statement: The field is only visible if the Current Page value is "360 Camera Rental".
Only local images are allowed.

These conditionals work fine when the form is embedded as a block on a page. It is when I call it out with the dialog settings that it stops working. I take the code from the Dialog Settings group.
Only local images are allowed.

And place it in the body of the page.
Only local images are allowed.

Press the button titled "Get A Quick Quote" and the dialog box pops up displaying the form.
Only local images are allowed.

However, there should be the field "360 Camera Model" in between the "Zip/Postal Code" and "Quantity" fields. Since the form is being called as its own node over the page, the page title does not match up with conditional statement and does not display the appropriate field.

How can I get the conditions to fire as I would like them to in this situation?

ericroks’s picture

FileSize
409.83 KB
jrockowitz’s picture

You need to use the [webform_submission:node:title] token and have to manually pass the entity type and id in your link.

<a href="/wf/form/issue-2989923?entity_type=node&entity_id=123" class="webform-dialog webform-dialog-normal button">Test Normal</a>

You will also need to configure 'Allow all elements to be populated using query string parameters. (/admin/structure/webform/manage/{WEBFORM_ID}/settings/form)


I need help documenting how custom dialogs work within the webform module.

jrockowitz’s picture

The attached patch makes it a little easier for developers to enable 'Allow (dialog) source entity to be populated using query string parameters'.

  • jrockowitz committed e4b097d on 8.x-5.x
    Issue #2989923 by jrockowitz, ericroks: Dialog Modal...
jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Please download the test dev release to review.

ericroks’s picture

FileSize
506.74 KB
589.15 KB
625.61 KB
285.57 KB
391.86 KB
351.87 KB

Ok, I started off by adjusting the token in the hidden field.
step 1

Changed it to [webform_submission:node:title].
step 2

Navigated to /admin/structure/webform/manage/MY_FORM/settings/form and checked the box for "Allow source entity to be populated using query string parameters".
step 3

Then, went to /admin/structure/webform/manage/MY_FORM/settings and copied the code for the "Custom" option.
step 4

Pasted into the body of the node (ID: 27). Then customized the link to use node for the Entity and 27 for the ID. Hit save.
step 5

Clicked on the "Test Custom" link and the dialog box popped up without the proper conditional responding.
step 6

I then submitted a test of the form and looked at the email for the hidden field content. In the message it returned: Current Page [webform_submission:node:title]. It should have returned "360 Camera Rental" as that is the title of node 27.

Am i missing something here?

ericroks’s picture

PS. I saw that you could use some help on the documentation. I can help if you let me know what, specifically you need done.

ericroks’s picture

PPS. I failed to mention that I also manually updated the Webform module to the latest Dev release and ran update script.

jrockowitz’s picture

Status: Fixed » Needs work

@ericroks #13 looks right. I will try to find sometime to replicate your steps and see what is wrong.

Once we sort this out, it would help everyone if we could create a recipe

ericroks’s picture

Sure, I can help with the recipe. It's the least I can do to give back for all of the help received.

  • jrockowitz committed 0e75afa on 8.x-5.x
    Issue #2989923 by jrockowitz, ericroks: Dialog Modal...
jrockowitz’s picture

The attached webform replicates the issues when it is attached to a webform node that supports 'Full HTML' in the body content.

  • jrockowitz committed e1eeb66 on 8.x-5.x
    Issue #2989923 by jrockowitz, ericroks: Dialog Modal...

  • jrockowitz committed d731bb7 on 8.x-5.x
    Issue #2989923 by jrockowitz, ericroks: Dialog Modal...
jrockowitz’s picture

Doh!!! I failed to read my own documentation.

entity_type needs to be source_entity_type and entity_id needs to be source_entity_id.

<a href="/wf/form/issue-2989923?entity_type=ENTITY_TYPE&amp;entity_id=ENTITY_ID" class="webform-dialog button" data-dialog-options="{&quot;width&quot;:400,&quot;height&quot;:400}">Test Custom</a>

jrockowitz’s picture

Status: Needs work » Needs review
ericroks’s picture

I'll give it a try.

ericroks’s picture

FileSize
356.96 KB
413.31 KB
629.54 KB
570.42 KB
517.61 KB

I was not able to produce the desired results for my form in question. Below are the steps that I took:

First, I edited the hidden field that contains the Title token;
step 1

Next, edited the token used in that hidden field to [webform_submission:source-entity:title]
step 2

Navigated to the Dialog Settings and grabbed the stock code for the "Custom" option.
step 3

The fourth step, pasted the code into the body of the node I am editing (Full HTML, of course) as seen below.

a class="webform-dialog button" data-dialog-options="{"width":400,"height":400}" href="/form/quick-quote-form?source_entity_type=node&source_entity_id=27"

step 4

Hit Save.

Edited page loads and I click "Test Custom". The dialog box appears, however, the form is unable to load.
step 5

ericroks’s picture

In addition, here is the .yml export for reference.

jrockowitz’s picture

The issue with your webform is the 'Type of source entity to be populated using query string parameters' needs to be blank or set to 'Content' (aka node) and not 'Field'

@see /admin/structure/webform/manage/quick_quote_form/settings/form

ericroks’s picture

Changed Type of source entity to be populated using query string parameters to "Content" instead of "Field". That did bring the form back to the dialog box. But, still does not show the conditional field.

Submitted a test from that form and the entire field "Current Page" was totally excluded in the resulting email.

ericroks’s picture

Oh, never mind. It worked!!!

I double checked the hidden field "Current Page" and saw that the Default Value was populated with the appropiate tag but the Value field was blank. I added [webform_submission:source-entity:title] to the Value field and it worked! I have the conditional field in there now.

Thank you very much for the assistance!

jrockowitz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

liquidcms’s picture

I guess the recipe for this was never put together?

Trying to do what seems like the same thing but no luck. Some things have possibly changed? There is no longer a Dialog Options; but i think just to provide help for the dialog url.

I have tried this:

<p><strong>Is there a problem with this page? <a class="btn webform-dialog webform-dialog-narrow" href="/en/form/user-feedback-form?source_entity_type=node&amp;source_entity_id=1187">Report problem</a></strong></p>

both in a block and on the node page. both give same result for this token: [webform_submission:source-entity:title] which is the title of the webform; but the page it is sued on.