Handle onSubmit callback from typeform in Android and iOS | Community
Skip to main content
Answered

Handle onSubmit callback from typeform in Android and iOS

  • August 19, 2022
  • 7 replies
  • 1185 views

I want to call some function in app once user submits the typeform. I know submit returns the  result callback in onSubmit() but how can I receive callback in app using this function name only? I checked the documentation but could not find anything related to mobile apps integration.

Best answer by mathio-tf

Hello @shivam.jaiswal and @Israel 

our embed SDK is written in JavaScript. You can execute any JS code in the onSubmit callback. See the docs on our dev portal about callbacks.

If you are using a JS framework (such as CapacitorJS) you can execute your JS code right in the callback.

I dont have much experience with building native apps. However if you are building a native app you could use this approach:

  1. display webview with local HTML page
  2. the page will contain Typeform embed SDK code, eg.
    <div id="form"></div>
    <script src="//embed.typeform.com/next/embed.js"></script>
    <script>
    window.tf.createWidget('<form-id>', { 
      container: document.querySelector('#form'),
      onSubmit: () => {
        // your custom code here
      }
    })
    </script>

     

  3. in the onSubmit method you can send data to your native code - see this Medium article on how to do this: https://medium.com/@sreeharikv112/communication-from-webview-to-native-ios-android-app-6d842cefe02d

View original

7 replies

Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • 14883 replies
  • August 19, 2022

Hi @shivam.jaiswal Thanks for stopping by the community! Right now, we don’t support forms embedded in apps, I’m afraid. Though, when @mathio returns from holiday, he may have some guidance to point you in the right direction. 😀


  • Navigating the Land
  • 2 replies
  • August 19, 2022

Thank you. @Liz I would also be interested on knowing if there’s a work around for this.


Thankyou @Liz for the response, looking forward for the solution.


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

Hello @shivam.jaiswal and @Israel 

our embed SDK is written in JavaScript. You can execute any JS code in the onSubmit callback. See the docs on our dev portal about callbacks.

If you are using a JS framework (such as CapacitorJS) you can execute your JS code right in the callback.

I dont have much experience with building native apps. However if you are building a native app you could use this approach:

  1. display webview with local HTML page
  2. the page will contain Typeform embed SDK code, eg.
    <div id="form"></div>
    <script src="//embed.typeform.com/next/embed.js"></script>
    <script>
    window.tf.createWidget('<form-id>', { 
      container: document.querySelector('#form'),
      onSubmit: () => {
        // your custom code here
      }
    })
    </script>

     

  3. in the onSubmit method you can send data to your native code - see this Medium article on how to do this: https://medium.com/@sreeharikv112/communication-from-webview-to-native-ios-android-app-6d842cefe02d


  • Navigating the Land
  • 2 replies
  • August 24, 2022

@mathio Thanks so much, seems to be working fine!


Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • 14883 replies
  • August 24, 2022

Yay! Glad to hear that worked, @Israel ! Let us know if there’s anything else we can help with. 😀


Forum|alt.badge.img
  • Explorer
  • 5 replies
  • January 29, 2024

I tried the same approach on Flutter app and getting the following warning on console:

I/chromium(12820): [INFO:CONSOLE(0)] "[Report Only] Refused to frame 'https://form.typeform.com/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' http://localhost:* capacitor: iconic: https:".


Reply