kobotoolbox / enketo-express

We've moved! Please use the new repository 🠊 https://github.com/enketo/enketo-express
Apache License 2.0
102 stars 90 forks source link

Allow forms to be dynamically pre-filled #1093

Closed jeverling closed 6 years ago

jeverling commented 6 years ago

It would be a great feature if Enketo would allow forms to be dynamically pre-filled. With the default column in a XLSForm, you can pre-fill a form with static values. However, it seems for some use-cases dynamic pre-filling of values would be useful, for example sending out links to different groups that will pre-fill the same form with different values. It might also help with reproducing problems, where you can send a link to a form that doesn't work as expected with specific data to someone else.

I think just url-encoding the answers to pre-fill could work well, e.g.

https://ee.kobotoolbox.org/x/#DpBV87r1?name=Jesaja+Everling&age=37

Another approach would be to "inject" XML into IndexedDB and to load it as a draft, but I think URLencoding should work good enough and is much simpler.

What do you think?

MartijnR commented 6 years ago

Hi @jeverling!

I totally agree, and Enketo actually has this feature (though only for online-only form views)! 👍🎉

It's just not exposed in the KoBoToolbox interface. You may want to request the feature or discuss a PR in one of the KoBo repos.

The feature is documented here: https://apidocs.enketo.org/v2#/post-survey (defaults parameter).

For offline-capable views, I'd prefer to use a 3rd option: external data (XML or CSV) and then use a calculation to populate questions. Enketo has been designed to facilitate serving different external data documents to different users (most feasibly by using the existing authentication).

cc @jnm

Feel free to re-open if you want to discuss an addition to Enketo.

jeverling commented 6 years ago

Hi @MartijnR, thanks for your fast reply! It's great to know that this functionality already exists. :)

marjetika commented 6 years ago

@jeverling - have you found any issues/discussion about this in KoBo? I need this functionality, too.

Y2KWebs commented 5 years ago

Hello!

I am trying to use this pre-fill feature on my self hosted instance of kobotoolbox, but can't figure out why is not working. I am using this URL, to populate visita_SPV. for example

http://67.205.154.75:8001/admincapris&form_id='aa84ppstK5QtruwFkgZBDZ'&defaults[/data/visita_SPV]=6699

or

https://ee.kobotoolbox.org/::KdZG6c4D&form_id='aa84ppstK5QtruwFkgZBDZ'&defaults[/data/visita_SPV]=6699

Can't get the correct sintaxis... what am I doing wrong?

thanks!!

MartijnR commented 5 years ago

what am I doing wrong?

You're not using the API to create the URL for you. Instead you're just guessing what you think the webform URL could perhaps be. Webform URL and passing data to the API have no syntax relation.