Skip to main content
Answered

How do I retrieve the current response after user fills in the form?

  • February 9, 2022
  • 8 replies
  • 1577 views

Hello,

So we’re trying to set up a survey in which the user is presented with a landing page based on what information they have filled. Now there’s a feature of conditionals in the typeform itself, but I didn’t find anything that would let us attach a link to a page based on what user has submitted.
 

Another option is to evaluate the responses of the form after user submits it, but I didn’t find anything in the SDK documentation. The responses API is there for downloading all responses at once, but is there a way to get current response after form is filled?

Best answer by mathio-tf

Hello @cherrygot 

you can recall information (use respondent answers) in your redirect links and build a link with query params based on their answers.

For a better integration you could use our embed SDK and retrieve the response on form submit and then process it. You can find details in this article I wrote:
https://medium.com/typeforms-engineering-blog/integrate-typeform-with-next-js-b27a5306bfbb

Response API can retrieve specific responses by supplying included_response_ids parameter (if you supply just one ID, it will return only one specific response).

View original

8 replies

mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • 888 replies
  • Answer
  • February 9, 2022

Hello @cherrygot 

you can recall information (use respondent answers) in your redirect links and build a link with query params based on their answers.

For a better integration you could use our embed SDK and retrieve the response on form submit and then process it. You can find details in this article I wrote:
https://medium.com/typeforms-engineering-blog/integrate-typeform-with-next-js-b27a5306bfbb

Response API can retrieve specific responses by supplying included_response_ids parameter (if you supply just one ID, it will return only one specific response).


Forum|alt.badge.img
  • Explorer
  • 7 replies
  • November 17, 2022

Hi @mathio ,

I looked at your example and it looks like you are retrieving the response answers using the response_id and form id. However, is not entirely clear to me how you were able to retrieve the `response_id`, in the code it seems to be passed to the function specified in onSubmit(), is that correct?

1
2
3const handleTypeformSubmit = async ({ responseId }) => {
4 const response = await fetch(`/api/response?formId=${formId}&responseId=${responseId}`)
5 if (response.ok) {
6 const { name, rating } = await response.json()
7 console.log(‘Form responses’, { name, rating })
8 // TODO: save name and rating in cookie
9 // and use it to personalize the tooltip
10 }
11}
12
13id={formId}
14 chat
15 tooltip={getTooltip()}
16 key={`${typeformName}-${typeformRating}`}
17 onSubmit={handleTypeformSubmit}
18 hidden={{
19 visitor_name: typeformName,
20 visitor_rating: typeformRating === null ? ‘’ : (isTypeformRatingGood ? ‘good’ : ‘bad’),

 


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • 888 replies
  • November 17, 2022

@Jver you are correct, the responseId is passed to onSubmit callback. It identifies the response that was just submitted.


Forum|alt.badge.img
  • Explorer
  • 7 replies
  • November 18, 2022

Thanks, I think I got it. Very helpful article when you read the github embed docs first


Forum|alt.badge.img
  • Explorer
  • 7 replies
  • November 18, 2022

I am running into one problem, when I have two typeforms to embed it stops working, as they both require the same parameters which run into a conflict:

1const { open, close, toggle, refresh } = window.tf.createPopup('id')
2

renaming the parameters like so breaks the functionality:

1const { open_2, close_2, toggle_2, refresh_2 } = window.tf.createPopup('id')
2
3document.querySelector('.my_class').onclick = toggle_2

Is there a fix for this issue?


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • 888 replies
  • November 18, 2022

In JavasScript you simplify it and do it like this:

1const popup1 = window.tf.createPopup('id1')
2document.querySelector('.my_class_1').onclick = popup1.toggle()
3
4const popup2 = window.tf.createPopup('id2')
5document.querySelector('.my_class_2').onclick = popup2.toggle()

 

It is not necessary to decompose the assignment into multiple variables. However if you really want to:

1const { toggle } = window.tf.createPopup('id1')
2document.querySelector('.my_class_1').onclick = toggle()
3
4const{ toggle: secondToggle } = window.tf.createPopup('id2')
5document.querySelector('.my_class_2').onclick = secondToggle()

 


Forum|alt.badge.img
  • Explorer
  • 7 replies
  • November 27, 2022

I have everything set up correctly, but I have one more question. I want to track utm parameters and have set them up similarly to the hidden variables, like in the code below. However, I am not receiving utm parameters in the submissions of the forms. Is there another way I should go about passing the utm parameters?

1const create_and_start_popup = (
2 nref,
3 oref,
4 source,
5 medium,
6 campaign,
7 content,
8 term
9) => {
10
11 const create_popup = window.tf.createPopup('<form_id>', {
12 hidden: {
13 'oref': oref,
14 'nref': nref
15 },
16 tracking: {
17 'source': source,
18 'medium': medium,
19 'campaign': campaign,
20 'content': content,
21 'term': term
22 },
23 onSubmit: async (data) => {
24
25 url = 'https://www.huurprijshulp.nl/bedankt/?form=nl&response_id=' + data.responseId
26
27 window.location.replace(url)
28
29 }
30 })
31
32 // start popup
33 create_popup.toggle()
34
35}

mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • 888 replies
  • November 28, 2022

Did you setup hidden fields in your typeform with utm_ prefix? If yes, then you need to name them accordingly in the tracking object (eg. not source but utm_source)..