Form in a collection page template- How to identify the page or item?

I have an important form in my collection page template. All I want to do is identify the collection page (or associated collection item) where the form was submitted.

I am hoping there is some basic method for this. Here are the workarounds I have explored:

  • Create a hidden form field with text from the collection. Looks like this is impossible.
  • Name a form field using text from the collection. Looks like this is impossible.
  • Name the form itself using text from the collection. Looks like this is impossible.
  • Use form labels in some way. Looks useless.
  • Having a hidden radio button using text from the collection. While the form frontend can pull CMS text, the form submission data can only be named “radio.”
  • Reference CMS data in a hidden select field. No dice.

Is there any way to use CMS data in a form to identify the collection page or reference the page’s collection item?

2 Likes

Here is the answer. Add a hidden embed to your form with this code:

In the embed, paste this code, which will dynamically create the hidden input field called pageURL and save the current url as part of the form data submitted:

<script type="text/javascript" language="JavaScript"><!--
document.write('<input ');
document.write('   type="hidden" ');
document.write('   name="pageURL" ');
document.write('   value="' + document.URL + '">');
//--></script>

When the user submits the form, the current url will get submitted.

12 Likes

Thank you, @dforeman. This is super helpful.

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