Streaming live at 10am (PST)

Add slug or cms data to form submissions


#1

Is there a way to add slug or cms data to form submissions? We are going to implement a general form on a dynamic page, and it would be nice for the client to see which page the form is coming from.


#2

Yes, possible. Implement the form, then ask again with share link AND published link.


#3

Ok, cool.
I know you have to publish share link, but form was not done, and I wanted to explore different options before selecting form approach. We have made a simple webflow form on the page now.

Here is the share link:
https://preview.webflow.com/preview/bax?preview=bdb3000eb808d21a5edca510f90b00e7

And link to page with form:
https://www.baxas.no/advokat/strafferett


#4

Paste this in Site Settings > Custom Code > Header Code:

<script>
function getParam(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); }
</script>

Paste this in Page Settings > Custom Code > Footer Code:

<script>
$('#Navn-2').val(getParam('Navn-2'));
</script>

Now, this link will populate first field with value "test":

https://www.baxas.no/advokat/strafferett?Navn-2=test


#5

Hmm...not sure if I explained my challenge good enough. I want form submissions from these dynamic pages to include "slug" or some other CMS data so that form entries can be handled correctly by client.

So data from this specific page could be:
Name: Tom Hansen
Phone: 995 56 856
Email: tom@hansen.com
Comment: Bla bla bla
Page: Strafferett

Where "Page" is the dynamic data. Client will then know what kind of area the customer is interested in.


#6

Just add an embed code with a link/button and dynamic variable like this. (hide the referrer field if you don’t want to display it to the user).

http://sandbox-903b9c.webflow.io/post/blog-post-1
http://sandbox-903b9c.webflow.io/post/blog-post-2

Otherwise, JS can also grab the referring page automatically using location.referrer.


#7

Thank you @samliew. I will give it a go.


#8

I actually thought of a simpler way to do this. I just added a dynamic embed to the form and a hidden input field with dynamic value. The dynamic embeds usually solve it :slight_smile:

<input type="hidden" name="Fagfelt" value="(Slug / dynamic value)">

#9

Hi
It seems you have the solution to my problem, but I can’t make it work. I don’t see a way to make a hidden input field with a dynamic value. Is there not a way to directly call a CMS field content for the value?
In your example: "input type=“hidden” name=“Fagfelt” value=“(Slug / dynamic value)” Can I not directly enter the CMS field in question?
In case I’m not making sense: I simply need the form to submit the page name along with the form content (the purpose are applications).
Many thanks,
Gaudenz


#10

@Gaudenz

The code is input into an html embed which is added inside the form block. Replace the value inside the quotes “” with the slug or name from the CMS.

Hope that helps.


#11

@Gaudenz

Add a HTML Embed inside the Form component.
See screenshot.

Add a dynamic field inside the “hidden” input field in the HTML Embed, and give it a proper name.
See screenshot.

Good luck!


#12

Thanks very much to both @matthewpmunger and @biodust - It worked! (I wasn’t aware of the “Add Field” option in the HTML Embed Editor.)
Funny enough, the value returns only the first word of the form content (e.g. “Manager” for the field content “Manager Corporate Development”) - however, it works with the slug which is good enough for me!
Thanks again & cheers,
Gaudenz


#13

Awesome! Glad it worked out.