Muut
December 15, 2016, 8:16pm
1
Hey guys,
I have set up a nice website which includes the same frontend form on each page. Is there a possibility to get the page (page url, title …) where the contact form is sent from? I thought of doing this with a hidden form field, but this lacks some documentation on the learn.grav page.
I want to find out which pages are generating the most leads
Could someone help me out with this?
Muut
December 15, 2016, 8:39pm
2
You can use the hidden field and evaluate the default value:
-
name: page
type: hidden
default: grav.page.route
evaluate: true
Muut
December 19, 2016, 6:18pm
3
Thanks it seems to work. Just two more questions:
The hidden field is visible on the “thank you page” after the form is sent. Any chance to prevent this?
What does evaluate: true
do?
Muut
December 19, 2016, 8:01pm
4
HTTP headers include that data as a referer (yes the spec is misspelled), along with with some other fun data.
In PHP, you can access the header variables like $_SERVER['HTTP_REFERER']
.
http://php.net/manual/en/reserved.variables.server.php
Note: the HTTP headers can be modified. Do not use this as a way to protect sensitive data. It is great for marketing insights as it will be accurate 99% of the time.
Muut
December 20, 2016, 9:10am
5
You can customize the thank you page by editing that page twig template, which by default is the very generic https://github.com/getgrav/grav-plugin-form/blob/develop/templates/formdata.html.twig . evaluate
is going to process the default value using Twig.
Muut
December 20, 2016, 8:23pm
6
Alright. Already thought of doing this. Any hint on how to filter hidden input fields?
{% if not field.type == hidden %}
does not work.
Muut
December 21, 2016, 3:54pm
7
I think {% if not field.type == "hidden" %}
will work. It’s a string, not a variable.
Muut
December 21, 2016, 8:31pm
8
Hmm thanks, but unfortunately it still does not work
Am I missing something else?
Code snippet from data.html.twig
{% if not field.type == "hidden" %}
<p class="sent-message__text">{{ string(form.value(field.name ?? index))|nl2br }}</p>
{% endif %}
---
Muut
December 21, 2016, 8:34pm
9
Got it… {% if field.type != "hidden" %}
works!