I created a form that work fine.
Upon validation, it just redirect the visitor to an url that is customized based on data entered by user in the form.
This is the bottom part of the form in the frontmatter:
buttons:
-
type: submit
classes: 'button buttonlight'
value: ' '
process:
-
redirect: 'https://www.example.com?arrival={{ form.value.date_arrival|e }}&departure={{ form.value.date_departure|e }}¶meter_1={{ parameter_1 }}¶meter_2={{ parameter_2 }}'
Visitors are then sent to https://www.example.com?arrival=2022-06-22&departure=2022-06-23¶meter_1¶meter_2
Dates of that url are those entered by the visitor in the fields date_arrival
and date_departure
of the form.
Because I will end up having many of these forms, because these forms are almost all identical except parameters 1 & 2 that will be in each page’s frontmatter, I am considering creating the form in my_form_template.html.twig template, instead of the page’s frontmatter.
Should I require to modify the forms, this will allow me to do it in the template, once for all forms, instead of modifying all the pages one by one.
I tried the beginning of my form as:
<form name="form_no_20" action="https://www.example.com?arrival={{ form.value.date_arrival|e }}&departure={{ form.value.date_departure|e }}¶meter_1={{ parameter_1 }}¶meter_2={{ parameter_2 }}" method="POST">
The validation of the form redirects but the url does not include the data entered by the visitor.
I tried setting {% set date_arrival = form.value.date_arrival %}
and replacing {{ form.value.date_arrival|e }}
by {{ date_arrival }}
in the url, but no change.
Am I trying to do something that I cannot do without some php/js (not within my skills) or am I just missing something?
Thank you for your help.