Skip to content
Grav 2.0 is officially stable. Read the announcement →
Plugins

Pass value to thankyou page or email plugin

Solved by Jens Vogel View solution

Started by Jens Vogel 6 years ago · 4 replies · 769 views
6 years ago

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.

6 years ago

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:

YAML
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:

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

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

last edited 05/24/20 by Ron Wardenier
6 years ago

Hi @bleutzinn, thank you for your answer.

TWIG
{{ 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)?

PHP
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.

6 years ago

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

PHP
$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
6 years ago Solution

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

Solved my problem by using simply

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

for save file, and

TWIG
{{ form.uniqueid() }}

for the thankyou page to file download.

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 75 1 week ago
Plugins · by Xavier, 4 weeks ago
2 81 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1208 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 75 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 99 2 months ago