How to include current URL in a form?

Hi,

is there an easy way how to include the current URL in a form?

I am building a project with approx. 60 pages that all include a form that I want to set up as a symbol. When I receive a mail from one of the forms - of course I have to find out the URL of the respective page.

Is there a easy way to automatically include the URL in the form?

The alternative option would be to set a hidden field, but in that case I would have to edit this hidden field on each form separately and I won’t be able to use it as a symbol.

Thanks in advance.

Michael

Nobody has an idea how to handle this issue?

Have you tried the jquery route.

Use jquery to populate a generic field (onLoad) with a preset pre-determined form name based on the url.

Hi @michael, one option is to use a little javascript in an embed widget

<script type="text/javascript">
            
document.getElementById('pageurl').value = window.location.href; 

</script>

Where pageurl is the form field with unique ID = “pageurl”

You might try that and see if this works:) Just drop an embed widget in your form wrapper, just before the submit button.

3 Likes

Hi @cyberdave,

thanks for your reply.

Just adding the js code won’t make the URL apprear in the mails sent by the form mailer, right? How does the additional code have to look like in ordner to include the URL as a hidden field?

<input type="hidden" id="pageurl"  name="pageurl" value="pageurl" /> 

… that line is not correct, right :wink:

Can I put the field in the same embed widget as the js code? An does the input fiel have to be before or after the js code?

Thanks a lot for your support!

Michael

… I might have found a solution …

<script type="text/javascript">
            
window.onload=function()
{document.getElementById('pageurl').value = window.location.href;}

</script>

<input type="hidden" id="pageurl"  name="pageurl" value="pageurl" />

… seems to work fine.

Is that option ok or is there a better way (to write the code)?

Thanks!

All the best,
Michael

UPDATE: One last problem remains … I got 4 forms on each page and all form should include the URL. It works for one form but the other forms show “pageurl: pageurl” in the mail, when I include the identical embeded widget. Any idea?

2 Likes

Hi @michael, You would probably have to include the javascript code 4 times, each code snippet using a different ID for the hidden field in each form.

If you have a published url and read-only site link, I am happy to take a further look : https://help.webflow.com/faq/how-do-i-share-my-sites-read-only-link

Cheers,
Dave

JQuery. You can do it in JQuery.
Here’s the visual process to get it done.

Video:
http://quick.as/J4x1C9g5y

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.