Dynamically add page url to contact form

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?

You can use the hidden field and evaluate the default value:

        -
            name: page
            type: hidden
            default: grav.page.route
            evaluate: true

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?

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.

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.

Alright. Already thought of doing this. Any hint on how to filter hidden input fields?
{% if not field.type == hidden %}does not work. :frowning:

I think {% if not field.type == "hidden" %} will work. It’s a string, not a variable.

Hmm thanks, but unfortunately it still does not work :confused:
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 ?&quest; index))|nl2br }}</p>
{% endif %}
---

Got it… {% if field.type != "hidden" %}works!