> For the complete documentation index, see [llms.txt](https://atd-dts.gitbook.io/atd-knack-operations/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://atd-dts.gitbook.io/atd-knack-operations/knack/url-parameters-to-populate-a-form.md).

# URL Parameters to populate a form

A how-to guide on prepopulating a form based on the URL parameters for Knack applications

{% hint style="info" %}
Official Knack [Documentation](https://learn.knack.com/article/z36i2it02b-how-to-use-url-variables-to-pre-populate-a-form)

Here's what is super frustrating, the encoder link the documentation included was changing spaces to `+` instead of `%20`.
{% endhint %}

DTS Documentation in Issue [#5735](https://github.com/cityofaustin/atd-data-tech/issues/5735)

`{"field_390":"Finance & Administration","field_398":"Bug Report — Something is not working","field_399":"Finance & Purchasing"}`

Example of form Link with URL parameters:

<https://atd.knack.com/dts#new-service-request/?view_249_vars=%7B%22field_390%22%3A%22Finance%20%26%20Administration%22%2C%22field_398%22%3A%22Bug%20Report%20%E2%80%94%20Something%20is%20not%20working%22%2C%22field_399%22%3A%22Finance%20%26%20Purchasing%22%7D>

<https://www.urlencoder.org/> <-- this link will change the spaces to `%20`

{% stepper %}
{% step %}

### Get the default form URL

In the example, we are going to be using the service request form <https://atd.knack.com/dts#new-service-request/>
{% endstep %}

{% step %}

### In that same URL, determine the field IDs and what you wish to prepopulate it with and follow this template

The template is:

{% code overflow="wrap" %}

```
https://atd.knack.com/dts#new-service-request/?VIEW_ID_vars={"FIELD_ID":{"id":"RECORD_ID"},"FIELD_ID":"YOUR MULTICHOICE TEXT"}
```

{% endcode %}

`VIEW_ID` as in the form.

`FIELD_ID` as in the field you wish to populate it with

`YOUR MULTICHOICE TEXT` as in what you wish the form to be prepopulated with for a **multichoice** field.

`RECORD_ID` as in what you wish the form to be prepopulated with for a **Connection** field.

{% code overflow="wrap" %}

```
https://atd.knack.com/dts#new-service-request/?VIEW_ID_vars={"FIELD_ID"%3A{"id"%3A"RECORD_ID"}%2C"FIELD_ID"%3A"YOUR MULTICHOICE TEXT"}}
```

{% endcode %}
{% endstep %}

{% step %}

### Use a URL encoder so that the URL link is valid on Rich Text and buttons on the app

While the URL would work from copy/paste, it does not work when putting it on a button or as a link as it needs to be encoded in order for it to redirect correctly instead of a redirect error page.

Use <https://www.urlencoder.org/> to change:

* Spaces `%20`&#x20;
* Curly Brackets `%7B`
* You can view the [list of ASCII Encoding Reference on W3](https://www.w3schools.com/tags//ref_urlencode.asp)

The only part that needs encoding is after the `/?` of the URL

[`https://atd.knack.com/dts#new-service-request/?view_249_vars=%7B%22field_1101%22%3A%7B%22id%22%3A%226840d1f6e5440702b490127a%22%7D%2C%22field_398%22%3A%22Feature%20or%20Enhancement%20%E2%80%94%20An%20application%20I%20use%20could%20be%20improved%22%2C%22field_1130%22%3A%7B%22id%22%3A%225c4f3e24519c45086bd0b059%22%7D%7D`](https://atd.knack.com/dts#new-service-request/?view_249_vars=%7B%22field_1101%22%3A%7B%22id%22%3A%226840d1f6e5440702b490127a%22%7D%2C%22field_398%22%3A%22Feature%20or%20Enhancement%20%E2%80%94%20An%20application%20I%20use%20could%20be%20improved%22%2C%22field_1130%22%3A%7B%22id%22%3A%225c4f3e24519c45086bd0b059%22%7D%7D)
{% endstep %}
{% endstepper %}
