Capture the submission page URL when a Drupal 7 webform is submitted
This lesson shows you a way to capture the submission page when someone submits a Drupal 7 webform on your website. This is useful if you have a webform in a block on multiple pages, and you want to know which page someone was on when they submitted the page.
Here's a scenario:
- You have created a product enquiry form using the Webform module in Drupal 7.
- You have configured the webform to be available as a block, and placed that block on all product pages.
- When the form is submitted by a visitor to your website, you want to track which page the visitor was on when they completed the form.
To do this:
- Add a Hidden field component to your webform. Give it a name such as "Page where form completed".
- In the Default Value field, click Browse available tokens. If you don't see this option, you'll need to install the Token module first.
- In the list of tokens, look for a section called Current Pager (as shown above), then choose one of the tokens from there, e.g.
Note that you can add any token from the list that you like, including field values for the node. However, you'll need to make sure that the field actually has a value for that node type, otherwise the field will be empty when the form is submitted.
- Copy and paste your chosen token into the Default Value field. I recommend you only place one token in this field. Add extra hidden fields if you want to track more than one token. This will make it easier to analyse your data later, particularly if you export the webform results to a CSV file.
- Finally, choose the Display option (either Secure Value or Hidden Element). Secure Value is the best option if you're using tokens here.
- Click Save Component.
Now, when someone fills in the form, the submission will include the page they were on when they submitted it.