Can I dynamically pre-populate values into a dropdown field | Community
Skip to main content
Answered

Can I dynamically pre-populate values into a dropdown field


savantlywayne

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. 

Best answer by mathio-tf

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.

View original

Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • October 23, 2023

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. 


savantlywayne

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?


john.desborough
Forum|alt.badge.img+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


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • October 24, 2023

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.


savantlywayne

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


okdashcam
Forum|alt.badge.img
  • Explorer
  • October 26, 2023
savantlywayne wrote:

@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

mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • October 27, 2023

Thank you @okdashcam for the example 👍

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


Reply