Streaming live at 10am (PST)

Populate form field with CMS content - code not working ugh

I cannot get the field to populate. What am I doing wrong?


Here is my public share link: LINK
(how to access public share link)

No need for jQuery her. Add embed hidden html feild inside your form and that’s it.

The idea her:

Update if this is ok. If not i will look at your page later.

Take it out of the </body> tag and instead add an Embed element to the form. Then add the following inside the Embed element, replacing <add cms Slug field here> with the dynamic cms field you selected:

<script>
	var Webflow = Webflow || [];
	Webflow.push(function() {
  		$('#slug').val('<add cms Slug field here>');
	});
</script>

Did that fix it?

P.S.

If not, please double check that ID for your field, in your Webflow Designer, has the same spelling and case:

Screen Shot 2020-03-22 at 1.37.53 AM

Hey Chris,

I have a question to add on to your code. I am using the code dynamically. A problem that I have ran into is that it only works on the first dynamic input item and does not show correct item.

I have place a collection list within a collection template, so I have had to use an embed as I need the collection items. How do I make the code find the right item and repeat form each item on the list?

Eben

Sorry, I’m not following you. Could you provide more detail?

Hey Chris,

Sorry for the late reply and thanks for getting back in touch. So the best way that I can think of getting may point across is with examples :slight_smile:

Here is the share link: https://preview.webflow.com/preview/ebens-amazing-project-9febc8?utm_medium=preview_link&utm_source=designer&utm_content=ebens-amazing-project-9febc8&preview=60051cbc10589c3dc1a83b34b7c15172&pageId=5f476e59c3a17f7c8ce60b65&mode=preview

So in the example you can see that I have a Collection list within the a collocation template. The collection list has 5 items within it. In the Collection Holder Template I have placed a collection list that is linked to the “Collection List” showing the 5 Items.


Collection List within the Collection Template “Collection Holder”


5 Items within the “Collection Lists”

Using a form to add the input element and then an embed within the form to add your code you can see that Webflow is a bit confused when the site is published.

When the site is published there is only one result retrieved and it’s the wrong item. It’s getting the last item within the collection and only populates the first input element of the collection list.

So I’m wondering if it is possible to add to the code to find the right item that corresponds to the collection list item.

Hope this makes more scene and thanks again for your help :slight_smile:

Eben

@Eben_Meyers I took a very quick peek at what you’ve done, at first glance it’s obvious it won’t work due to the fact that your code is pointing to the same text field id on each embed:

$('#Input').val 

Try changing the ID for each text field and change the corresponding “Input” value on the script.