Answered

Handle onSubmit callback from typeform in Android and iOS

  • 19 August 2022
  • 7 replies
  • 904 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.

icon

Best answer by mathio 23 August 2022, 11:59

View original

7 replies

Userlevel 7
Badge +5

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. 😀

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.

Userlevel 7
Badge +5

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

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

Userlevel 7
Badge +5

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

Userlevel 1
Badge

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