# Passing data to your form

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](/embeds/script-embed) layout through the `answers` option.

## 1. Enable "Get value from URL" on a field

1. Open the form in the **Build** section of forms.app.
2. Select the field you want to prefill.
3. In the field's settings, turn on **Get value from URL**.
4. Copy the field ID shown, the part between `#` and `=`.


## 2. Pass the value in your embed code

Add an `answers` key to the `options` object, alongside `width` and `height`. It maps field IDs to the values you want prefilled:

```html
<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.

## Reading the value from your own page's URL

forms.app doesn't parse your page's query string automatically. Read the value yourself, before constructing the embed call:

```html
<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.

## Capturing the full page URL

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`:

```html
<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>
```

Hide the field
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.

## What's next

- [Examples](/embeds/examples) for the idiomatic way to read query parameters in React, Next.js, Vue, and Kotlin.
- [Script embed](/embeds/script-embed) for the full `formsapp()` reference.