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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Chaining Forms and accessing values

form

Started by Harald Röhling 4 years ago · 2 replies · 554 views
4 years ago

Hi everyone,

I am trying to build a site with 2 forms. The first form is for the user to enter all relevant information, the 2nd one should be a page displaying the information and a checkbox of the type: 'are you sure?'

So far I used the display process to go from the 1st to the 2nd form. Using
{% include "forms/data.html.twig" %}
and
{% include "forms/secondForm.html.twig" with { form: forms(secondFormName) } %}
in the template to show the data and add the 2nd form on that page.

My problem is, that a mail should be send after submitting the 2nd form. But the email-adress is entered in the first form, also it should send information from 1st and 2nd form. Is there a trick to do it or will I have to rethink my approach?

4 years ago

I think I'd go with a single form and JS
When user submits first step, JS hides inputs and shows "Are you sure?". When user submits (s)he is sure, you do full form processing. You have all fields and a single form

4 years ago

A simpler UI/workflow as suggested by @Karmalakas is an excellent idea.

If you are still trying to solve this another way, you can access submitted variables in your target page template (by default, that's formdata.html.twig but you'll want to change that) using Twig expressions like form.data['email']. So you could set a hidden form field in your second form and set its value to something like "{{ form.data['email'] }}" then use that in your form's email action lower down. Make sure twig processing of frontmatter is enabled too. Sorry not tested yet and I can go into more detail if you still need.

You can probably also use the Sequential Form plugin, though it's probably overkill, possibly outdated, and I have never tried it.

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1140 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 63 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 138 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 114 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 132 7 months ago