Answered

How to build a loop?

  • 18 March 2022
  • 7 replies
  • 585 views

Userlevel 1

Hi there,

 

I am new to typeform and am making it work on my own - so far.

What I want to achieve:

Collect numbers per country. Only for selected countries.

That I have achieved. Example, someone ticks France, Germany, USA and Japan they will be prompted with entry forms for each of the ticked countries and not all the others.

 

What is missing:

I want to repeat the above for a previously selected group of people, e.g. “business man”, “sales man”, “worker”, “taxi driver”, etc.

So, if someone ticks “worker” and “taxi driver” and in the next step selects (e.g.) three countries they should see 6 windows (3 countries for “worker” and 3 countries for “taxi driver”).

(the above is an example, in total I have 19 stakeholders and 22 countries)

 

I started with question groups but am unable to get it right.

Anyone here who did something similar and can share an example?

 

Thank you very much,

   Tim

icon

Best answer by john.desborough 22 March 2022, 20:32

View original

7 replies

Userlevel 7
Badge +5

Hi @Tim Irfan Welcome to the community! Happy to have you here. :grinning:

It sounds like you’ll want to use this process to show only the questions that apply based on the previous answers. 

One thing to note is that it’s not possible to set logic jumps based on the phone field, so it might be helpful to have a question asking for the respondent’s country. 

Userlevel 1

Hi Liz,

 

 

thank you for the swift reply. Very helpful!

 

It works, but is pretty tedious. I’ll need to create 19 question groups, each with 22 countries and correct branching to only show the relevant countries. That’ll take hours to set up.

Any chance to code/program this or to create a loop (which would require the logic to jump back)?

 

Thank you,

   Tim

Userlevel 7
Badge +5

Hi @Tim Irfan You could use the Create API to build the form, but I’m not sure if this would help save a ton of time. 

Userlevel 7
Badge +6

@Liz  @Tim Irfan - just a thought from voice number 4 in my head… a bit convoluted at the moment but the gist it is this: 

  • create typeform 1 (hear me out!) with the select of the countries
    • if you start with selecting 1 country you can stream the user through selection of the group of people and send them to the individual question groups about those group-types ie
      • qgroup 1 - businessman
      • qgroup 2 - worker
      • qgroup 3 - taxi driver 
      • etc
    • you would need to have the questions for each group in the group
    • on q1 you would set up logic rules like this: 
      • if q1 answer = businessman jump to qg1
      • if q1 answer = worker jumpt to qg2
      • if q1 answer = taxi driver jump to qg3
      • etc
      • this would push the user to the first question group selected by the user
    • in the question groups you would need to have a logic rule on the last question in the group that says this - i have used qg1 as the example:
      • in qg1
        • if q1 answer = worker jumpt to qg2
        • if q1 answer = taxi driver jump to qg3
        • repeat for all possibilities 
        • if no other selected jumpto ending 
      • in qg2
        • if q1 answer = taxi driver jump to qg3
        • if not other selected jumpt ending 
      • in qg3 
        • jumpto ending
    • submit the answer and go to the ending page
    • on the ending page, ask tell the user that to enter data for another country they have to click the button available to send to user to the same form BUT with a hidden field containing the name of the country that they just did
    • you can have the form check for the existence of the hidden field and if it has data in it, you can have the form start with logic based on the hidden field ie meeting a logic rule.. in this case you would go a duplicate of the country selection question BUT on this one you would display a message that you have already done Spain, for example. 

that’s one way but it would mean that you have one loop for each country on a single select

 

if you wanted to allow for multiple selects on the country question

  • (multiple and say up to 5 just for arguments sake) 
    • set up variable for each of the up to five countries ie if q1 = France then set country_1 = France; if q1 = Spain the set country_2 to Spain etc.. 
    • you could insert a counter variable to determine how many variables you need to fill it (based on the responses from the country selection add 1 to a counter as long as the counter is lte5) then after assigning a country to a country_x variable, reduce the counter by 1 and then if the counter is 0 then you don’t add any more - ie if 3 was the count, it would stop after country_3
    • send the user to an ending page with the link/button using hidden fields being passed to the next typeform (call it typeform 2) where you do the input for the selected group types for country_1
      • in the URL use something like “target_country” = country_1” for the first ending page but pass all the county_x variables in the string 
      • do the question groups like in the scenario above for country_1 in this pass of the typeform (ie select the group types and answer the questions) 
      • check to see that country_2 is not blank and if not blank then insert it into the URL to send the user to same form after setting the target_country variable to country_2
      • submit the form and send the user to the ending page
      • the button on the ending page has the ‘new’ target_country value and that can be used as the loop back to this entry form until such time as a country_x value is ‘ ‘ or country_5 is completed… (you could even send a counter variable based on the number of countries selected, reducing it with each pass through the form)  to define if there is another pass to make to send the user back to the form

i know that seems complicated but it using a completed form as part of the loop instead of looping inside a form. 

 

if that makes any sense at all.. lol

 

des

Userlevel 1

Hi des,

 

thank you for the two possibilities and detailed explanations.

I think I have started with your option 1, but have the respondent start with the stakeholder and then go through all countries. So, basically what you described just starting with B instead of A.

 

I need to review again your option B - in detail and with time. I’ll probably get to that early next week and will let you know.

 

Best,

   Tim

Userlevel 7
Badge +6

@Tim Irfan - lemme know if you need any clarity on those ramblings lol

 

des

Userlevel 7
Badge +5

Let us know how it goes @Tim Irfan !

Reply