0

I have a webform with Inline confirmation, AJAX enabled and saving of submissions disabled.

Is it possible to access the submitted values from the webform-confirmation.html.twig template?

I know that I can do this by adding token values to the Confirmation message in the WebForm UI. But I prefer to solve this by modifying the template.

My motivation for doing this is that I need to add a javascript snippet after the user has submitted the form. And I want to do it at the template level because I have a larger number of forms where I need to add the javascript snippet.

Cheers

Stian

0

You can access submissions using 'webform_submission' variable. I know the webform-confirmation template file doesn't mention that variable but, if you look closely to the controller you see there additional variable being passed to this template.

A screenshot of kint output for webform_submission variable

N.B on your form setting make sure to set confirmation type to be "age (redirects to new page and displays the confirmation message)"

And always the latest one on the array is your last submission.

Submission Array

1
  • This only works when saving of submissions are enabled, which I was hoping to avoid. – Stian S Feb 7 '20 at 12:47
0

webform_confirmation is a hook_theme so you can preprocess it yourmodule_preprocess_webform_confirmation , get webform_submission related ( $variables['webform_submission'] ) and create any variable you need into this preprocess. YOu will find all the variable here : template_preprocess_webform_confirmation() in webform module.

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.