How can I specify default values in a web form link?

There's a level of indirection in Enketo that I don't really understand. It's the same issue with return_url vs returnUrl from Ideas and extensions for Central public links - #8 by LN -- what you see in the API docs is how to request a link with defaults, not how to build one. I think maybe the idea was to make it possible to change the shape of the actual links but in practice those links get directly shared and so must be stable.

The query parameter to add if you already have a link to an Enketo form and want to have it filled with default values is d. It works like the defaults one you linked to: you specify the full XPath field path in square brackets and the value after =.

If you have a public link that looks like

https://<my-domain>/-/single/5c55f6?st=GKR7aV9

you can add &d[<some XPath path>]=<some value>&d[<some other XPath path>]=<some other value>:

https://<my-domain>/-/single/5c55f6?st=GKR7aV9&d[/data/text_widgets/string_widget]=foo

You can build the XPath path for a field by starting with /data/, adding any containing group names separated by /, and then adding the field name at the end.

4 Likes