Dynamic form field

Hello,
I would like to create a form field, which will receive the current page url it was launched from, or even better - the exact section in the page. The field should be hidden and sent with the form when it’s being submitted.
Is that doable?

Thank you,
Naama.

Hi @Naama, it is not possible to do that natively yet via the forms widget, but you can put an embed widget into your form, just above the Submit button.

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.

Some other script can be used to save the ID as well, if you play around with it. I hope this helps to give you some ideas.

4 Likes

Thank you very much for your answer @cyberdave.
Unfortunately, it’s not working, it looks like it’s not reading the javascript at all. Maybe I should include something in the ?

Hi @Naama, could you please provide a read-only link to your site:

Also can you please give a screenshot of where your form is in the navigator ? I am happy to take a look.

@cyberdave, this is the link to the website: https://preview.webflow.com/preview/folloze?preview=31edd4359289631f2e1377ff50294f22
I’ve also attached a screenshot of the navigator.

I really appreciate your efforts to help me.
Naama.

Hi @Naama, thanks for the update. I took a look at the embed with the script I sent you, and that seems ok, but when I try to open the request a demo form, an error message is generated that also shuts everything else down too:

My suggestion is to fix this error first, get the form working so that it pops up and is possible to fill in a form submission. Could you look at this error on the form popup first, then once that is working, it is easier to see if there is some problem during the form submit process.

Hi @cyberdave,

I’ve fixed this bug and now it seems like the form is working, I receive a thank you page after it’s being submitted.
The only thing that’s wrong is that it’s not creating a lead in Salesforce unless I add the “debug” and “debugEmail” fields to the form.
Do you have any idea why is this happening?

Thank you very much,
Naama.

Hi @Naama, I am sorry, I really do not know that answer to that question :-/

Webflow is not doing anything tricky or special here, we only POST the form data in a standard way.

The fields you setup in the Webflow form will be posted to the target specified in the ACTION property.

How that is processed once posted is on Salesforce side, so the thing to do is to check what documentation they may have on that. Maybe there is some test mode or something you are in on their side. Not sure really, but good thing to check :slight_smile:

Hello @cyberdave,

I really appreciate all your help so far, I will check with Salesforce.

Thank you,
Naama.

Hello @cyberdave.

I would really appreciate it if you would write me how to add this dynamic field the id name (button) it was submitted from.

Thank you very much,
Naama.

Hi @Naama, thanks for the followup.

Just so I understand, are you wanting to dynamically get the Section ID the form is nested within?

The example I provided was a basic example how to capture the page url dynamically. If you already know the section ID, you can also concatenate the strings to form a working url to the section:

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

If you need further help, you might need to get some custom coding work done for this. A good suggstion is to reach out to some jquery gurus out there for help a custom solution.

Thank you very much @cyberdave!

Thanks for this example @cyberdave

Made my own script for giving forms a ID to make each form unique ^^

<script type="text/javascript" language="JavaScript">
<!--
document.write('<input ');
document.write('   type="hidden" ');
document.write('   name="formsubmitID" ');
document.write('   value="' + new Date().getTime() + '">');
//-->
</script>
2 Likes

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