I have a hard coded form so not one generate directly within Freeway. I am using the same form throughout my site and wanted to add a piece of code that would capture the url of the page the form is submitted from.
I have taken a look online to see, but cannot isolate a particular piece of code that I could use.
Does anyone know of a simple piece of code I can add in to my form code to accomplish this?
Hi Nathan,
Is the form on a page that uses PHP already? If so I’d be inclined to have PHP echo the current page URL into a hidden input on the form. This will get set when the page is served and submitted to the form processor when the form is submitted.
If you don’t have PHP running on the page and would rather not change the file extension for SEO or discoverability reasons (although there are ways around these) then you can do the same sort of thing by using JavaScript to populate the hidden field when the page loads. This is less bullet-proof as it relies on the browser to do the work rather than the server but can also get the job done quite easily.
Here’s an example page where if you view source on the page you can see the PHP has populated the first hidden field. You’ll see JavaScript has done the same to the second if you use the Web Inspector. The original HTML, PHP and JS source code is linked so you should be able to see what is going on.
Regards,
Tim.
On 9 Dec 2013, at 10:44, BigG wrote:
I have a hard coded form so not one generate directly within Freeway. I am using the same form throughout my site and wanted to add a piece of code that would capture the url of the page the form is submitted from.
I have taken a look online to see, but cannot isolate a particular piece of code that I could use.
Does anyone know of a simple piece of code I can add in to my form code to accomplish this?
Hi Nathan,
I’ve yet to wok with Perch forms but I would imagine that you can add the hidden field in anywhere in the form as it doesn’t get rendered in the browser.
I’m not too sure why Perch needs the inputs to be perch-prefixed but I suspect it does something on the admin end to allow you to control the form or the data collected.
I’ll make a note to look into this when I have a second.
Regards,
Tim.
On 9 Dec 2013, at 15:44, Walter Lee Davis wrote:
Try leaving the perch: part off of the input definition. Make it just a normal input with a PHP echo inside the value attribute:
That should work. My guess here is that Perch is double-decoding your code.
That’s correct. There’s a fair bit of optional built-in processing that can be done by Perch if necessary: store submissions in the db or tie it into a MailChimp account etc.
Todd
I’m not too sure why Perch needs the inputs to be perch-prefixed but I suspect it does something on the admin end to allow you to control the form or the data collected.