Answered

Can I dynamically pre-populate values into a dropdown field

  • 22 October 2023
  • 7 replies
  • 274 views

Is it possible to use hidden fields to prepopulate a drop-down field with data that is read from an SQL table when loading an embedded Typeform?

For example, we maintain a list of store locations in a SQL table, which can dynamically change over time. as new stores come online and old ones close. One of the forms needs to ask which location they are responding to.

We do not want the manual overhead of amending the form dropdown each time a location changes but rathe read and populate from the table. 

icon

Best answer by mathio 24 October 2023, 09:58

View original

7 replies

Userlevel 7
Badge +5

Hi @savantlywayne Happy Monday! I’m afraid we don’t offer a native feature that would allow you to pre-populate fields from data outside of Typeform. You could pass the information in through hidden fields, if this would work for you. 

Hey Liz, thank you for responding. So, the contents of the drop-down cannot be added from an external source, but if I populate a hidden field, would I be right in saying that I still cannot add the contents of the hidden field to the drop-down?

Userlevel 7
Badge +6

@mathio - here’s one for you sir.. could the API’s be used to query the external data set and return the data list to be used as options in a drop down question (thinking of the Create API here.. )  - I don’t dabble in them but it seems that you have posted a couple of possible ways that might work .. not sure if that applies to drop downs, in terms of passing in the options via the API

 

just a thought

 

des

Userlevel 7
Badge +5

Hello @savantlywayne and @john.desborough 

yes, you could use the Create API to update a dropdown field in your typeform. If the values are not fetched dynamically for each respondent (eg. based on their previous responses) you could have a script that periodically fetches data from external source and updates your typeform.

@mathio  .. thank you for responding! Do you have any examples that I can look at? 

Userlevel 3
Badge

@mathio  .. thank you for responding! Do you have any examples that I can look at? 

  • Get form ID as {form_id}
  • Make PUT request (+ authentication) with new field + existing fields
PUT https://api.typeform.com/forms/{form_id}

{
"fields": [
{
"id": "new_field_id",
"title": "New Field",
"type": "short_text"
},
...existing fields...
]
}
  • Specify id, title, type for new field
  • OPTIONAL but recommended:
    • Retrieve form to confirm field added
Userlevel 7
Badge +5

Thank you @okdashcam for the example 👍

@savantlywayne you can find more examples on our developer portal.

Reply