Is it possible to create a hidden form field in Webflow that can automatically capture the URL or specific page section from which it was launched and include it when the form is submitted?
Yes, it is possible to create a hidden form field in Webflow that can automatically capture the URL or specific page section from which it was launched and include it when the form is submitted. This can be achieved by using custom code and JavaScript within your Webflow project. Here's how you can do it:
- Open your Webflow project in the Designer.
- Navigate to the page where you want to add the hidden form field.
- Add a new HTML Embed element to your page. You can find this element in the Add panel on the left side of the Designer.
- Double-click the HTML Embed element to open the code editor.
- In the code editor, enter the following code:
<input type="hidden" name="referrer" id="referrer" value="">
- Save and close the code editor.
- Select the form element on your page and go to its settings.
- Click on the Actions tab, and then click on the + Add Action button.
- Choose the Set Value action from the dropdown menu.
- In the Set Value action settings, select the Referrer field you added in step 5 as the target field.
- In the Value field, enter the following JavaScript code:
document.getElementById('referrer').value = document.referrer;
- Save your changes and publish your site.
Now, when someone visits your website and submits the form, the hidden form field "referrer" will automatically capture the URL or specific page section from which the form was launched. This value will be included when the form is submitted, allowing you to track the referring page or section.
Note: If you want to capture a specific page section instead of the entire URL, you can modify the JavaScript code in step 11 to extract the relevant portion using different methods, such as window.location.hash
.
With this hidden form field, you can easily track and analyze where your form submissions are coming from, helping you gain insights into your website's performance and user behavior.
Additional Questions:
- How can I automatically capture the URL of the page where a form was submitted in Webflow?
- Can I track the specific page section from which a form was submitted in Webflow?
- What is the best way to include referral information in a Webflow form submission?