How to get the URL of the last page in a submitted Form?

I have dynamic CMS pages with a Button that leads to a form page where people can submit said form. However I need to know the custom dynamic page where they came from, how do I achieve this?

Say I am on Page A, click Button, get forwarded to Page B where I fill out the form and submit it. How do I include the Page A Url in the submitted form data?

Hey Yusuf,

You’d do that with a hidden field, and document.referrer.
Try this;

Add a custom attribute to your form, of referrer. The value doesn’t matter, you can leave it blank.

Then paste this into your page’s custom case in the </body> section.

<script>
$(function() {
  
  $('form[referrer]').append(
    `<input type='hidden' name='referrer' value = '${document.referrer}'/>`); 
  
});
</script>
1 Like

Hi Michael, I don’t know why but somehow it didn’t work. However I have used your document.referrer to look for solutions and found this which worked: Grab referrer as hidden field