This requirement is very common: the form is embedded on the product page, and you want to know which product the user was viewing when they submitted the form. The core approach is to use "hidden fields" plus frontend JavaScript to write the current page URL or product name into the form before submission.
However, the specific implementation depends entirely on which form tool you are using. The capabilities and extension methods vary greatly across different platforms.
General Universal Solution (With Code Control)
If your website allows you to add JavaScript, this is the most reliable method:
Add a hidden field to the form (e.g., page_url, product_name).
Before page load or form submission, use JavaScript to obtain window.location.href (page URL) or product information from the page, and assign it to the hidden field.
Example code:
javascript
// Execute after form is loaded
document.addEventListener('DOMContentLoaded', function() {
var hiddenField = document.querySelector('input[name="page_url"]');
if (hiddenField) {
hiddenField.value = window.location.href;
}
});
Note: If the form is dynamically loaded via a popup or AJAX (loaded only when the user clicks), the above code may not capture it. In such cases, you need to use MutationObserver to monitor the form being inserted into the DOM, or bind the assignment logic to the form's submit event.
Built-in Features of Common Form Tools
If you are using a SaaS form builder, check whether it has built-in capabilities:
Form Tool Built-in Feature Notes
Jotform "Get Form Page URL" Widget Built-in, no coding required, automatically captures the embedding page URL
Gravity Forms gform_source_id_pre_save_entry Hook Can obtain the page ID where the form is located via PHP, suitable for WordPress
Constant Contact Modify embed code + custom fields Need to manually add var url = document.location.href; to the embed code
Microsoft Forms Not supported Officially confirmed no native capability to obtain the submission page URL
Product Name Acquisition
If you want product name instead of the URL, you need to read it from the page structure. For example, extract it from the product title element on the page, or use Liquid/template variables on e-commerce platforms (such as Shopify's {{ product.title }}).
Key Pitfalls
HTTP_REFERER is unreliable: Relying on server-side Referer may result in empty values or lost data due to browser privacy settings or AJAX popups.
Iframe embedding complications: If the form is embedded via iframe, window.location.href in the parent page is not directly accessible; you need to pass it through URL parameters or postMessage.
However, the specific implementation depends entirely on which form tool you are using. The capabilities and extension methods vary greatly across different platforms.
General Universal Solution (With Code Control)
If your website allows you to add JavaScript, this is the most reliable method:
Add a hidden field to the form (e.g., page_url, product_name).
Before page load or form submission, use JavaScript to obtain window.location.href (page URL) or product information from the page, and assign it to the hidden field.
Example code:
javascript
// Execute after form is loaded
document.addEventListener('DOMContentLoaded', function() {
var hiddenField = document.querySelector('input[name="page_url"]');
if (hiddenField) {
hiddenField.value = window.location.href;
}
});
Note: If the form is dynamically loaded via a popup or AJAX (loaded only when the user clicks), the above code may not capture it. In such cases, you need to use MutationObserver to monitor the form being inserted into the DOM, or bind the assignment logic to the form's submit event.
Built-in Features of Common Form Tools
If you are using a SaaS form builder, check whether it has built-in capabilities:
Form Tool Built-in Feature Notes
Jotform "Get Form Page URL" Widget Built-in, no coding required, automatically captures the embedding page URL
Gravity Forms gform_source_id_pre_save_entry Hook Can obtain the page ID where the form is located via PHP, suitable for WordPress
Constant Contact Modify embed code + custom fields Need to manually add var url = document.location.href; to the embed code
Microsoft Forms Not supported Officially confirmed no native capability to obtain the submission page URL
Product Name Acquisition
If you want product name instead of the URL, you need to read it from the page structure. For example, extract it from the product title element on the page, or use Liquid/template variables on e-commerce platforms (such as Shopify's {{ product.title }}).
Key Pitfalls
HTTP_REFERER is unreliable: Relying on server-side Referer may result in empty values or lost data due to browser privacy settings or AJAX popups.
Iframe embedding complications: If the form is embedded via iframe, window.location.href in the parent page is not directly accessible; you need to pass it through URL parameters or postMessage.

