Prefill fields or pass along context from your page, such as a referral code, a plan name, or a UTM parameter, into an embedded form. This works on any script embed layout through the answers option.
- Open the form in the Build section of forms.app.
- Select the field you want to prefill.
- In the field's settings, turn on Get value from URL.
- Copy the field ID shown, the part between
#and=.
Add an answers key to the options object, alongside width and height. It maps field IDs to the values you want prefilled:
<script src="https://cdn.formsapp.io/embed.js" type="text/javascript" async defer onload="new formsapp('69d4bd130b443bda40c8f65a', 'standard', {'width':'100vw','height':'600px','answers':{'63ebad419442ad0448b9e9b6':'XXXX'}}, 'https://eu.forms.app');"></script>answers accepts one entry per field you want to prefill; every value is a string.
forms.app doesn't parse your page's query string automatically. Read the value yourself, before constructing the embed call:
<script>
const params = new URLSearchParams(window.location.search);
const referral = params.get('ref') || '';
</script>
<script src="https://cdn.formsapp.io/embed.js" type="text/javascript" async defer onload="new formsapp('69d4bd130b443bda40c8f65a', 'standard', {'width':'100vw','height':'600px','answers':{'63ebad419442ad0448b9e9b6': referral}}, 'https://eu.forms.app');"></script>The two <script> tags run in the same page scope, so the onload handler in the second one can reference referral from the first.
To store the referring page's URL itself, rather than a single query parameter, enable Get value from URL on a short text field and pass window.location.href:
<script src="https://cdn.formsapp.io/embed.js" type="text/javascript" async defer onload="new formsapp('69d4bd130b443bda40c8f65a', 'standard', {'height':'formHeight','answers':{'FIELD_ID': window.location.href}}, 'https://eu.forms.app');"></script>If a field is only there to capture passed-in data and isn't meant for the visitor to fill in themselves, mark it hidden and read-only in the Build section.
- Examples for the idiomatic way to read query parameters in React, Next.js, Vue, and Kotlin.
- Script embed for the full
formsapp()reference.