How can I know which page the form was used?

By: Hendrik Ensing | Asked: 06/28/2022
ForumsCategory: How-toHow can I know which page the form was used?
Hendrik Ensing asked 2 years ago

I want to have the form on every page I list a product.
If the customer wants the product, or has questions about the product, they will ask me using the form that is located right below the product. So 100 product pages, each page with the same form below each product.
How can I know which product they are looking at?
How can I know on which page the form was filled in and sent?
 

 

Bobby Clapp replied 2 years ago

Are you manually creating products? What does the URL of a product page look like?

Hendrik Ensing replied 2 years ago

Yes I am manually creating prducts in wordpress.

Hendrik Ensing replied 2 years ago

That's how he is doing it.
I want to do a similar thing.

2 Answers
Bobby Clapp answered 2 years ago
You can insert your form on the page and add a field to collect the current URL. https://formidableforms.com/knowledgebase/using-dynamic-default-values-in-fields/#kb-get-the-current-or-referring-url [server param="REQUEST_URI"]
Rob LeVineRob LeVine answered 2 years ago

Bobby's answer is good if you want the URL.  If you want the page-id, then one wayI can think of is to have a field on the form that stored the page id and fill in its value with some simple jQuery when the page is rendered so it'll be saved when the form is submitted.
 
Something like this, assuming your field key is "xyz123".
jQuery(document).ready(function($){
var matches = document.body.className.match(/(^|\s)page-id-(\d+)(\s|$)/);
var pageid = matches[0]; // or use [2] if you want just the number
$("#field_xyz123").val(pageId);
});

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right