Pass value to thankyou page or email plugin

I created a plugin that fills form values into a pdf file.

What I would like to do now, is passing the filename to the thankyou page and attach the file to an email sent by the email plugin. Both should be configured in the form.md file as actions.

Thank you for consider a solution.

Hi @jenspepie, Welcome to the Grav forum!

All form values are available as Twig variables in the thankyou page. All you need to do is set Twig processing to enabled in the frontmatter of the thankyou page like this:

cache_enable: false
process:
    twig: true

Disabling the cache for this page is a kind of precaution. Maybe it’s needed, maybe it’s not.

Then in the markdown of the thankyou page you do:

{{ form.value('filename_of_the_pdf') }}

For sending the email you can ‘invent’ some custom action and handle it in your plugin.

Hi @bleutzinn, thank you for your answer.

{{ form.value('…')) }} 

works fine for “normal” fields.

But I obviously forgot to mention that the filename must be unique, so I have to tell the thankyou page somehow the filename (generated at runtime by the ‘invented’ custom action) OR I use unique_id or form-nonce.

I see the latter id’s in the debugging session but not within the data-array. How can I make use of this ( {{ forms.unique_form_id }} would be nice)?

items = {array} [4]
 data = {array} [4]
  name = "ABC"
  vorname = "DEF"
 __unique_form_id__ = "bhd5ce4bmt9uz1f2puql"
 __form-name__ = "XYZ"
 form-nonce = "44f441552a9e6bacd5a9062538d78403"

Hope I made it clear what I want to do. Thanks again for your time.

In general you can make any PHP variable in your plugin available as a Twig variable:

$twig = $this->grav['twig'];
$twig->twig_vars['filename_of_the_pdf'] = $filename_of_the_pdf;

You can do this in your custom action handler.

1 Like

Thank you @bleutzinn, I see, there’s a lot of cool stuff in Grav.

Solved my problem by using simply

$filename = $form->uniqueid . '.pdf;

for save file, and

{{ form.uniqueid() }}

for the thankyou page to file download.