Include hidden fiel after load | Community
Skip to main content
Answered

Include hidden fiel after load


Hi all,

Iโ€™m struggling now to pass an hidden value into a field with Typeform.

My actual value is loaded not on the loading of the page but after a loading of one external javascript and create a parameter to my url : example : ?custom=XXXXX

But when I create some script with PHP or Javascript to catch this parameter, itโ€™s blank because the value is created after the page loading.

Is there any chance to pass this value into my form. If yes how could it be done ?

Thanks by advance for your help

 

Best answer by mathio-tf

Hello @AurelienB 

you will need to use out embed SDK to embed your typeform asynchronously when your hidden field value is available. You can use JavaScript code like this one:

<div id="wrapper"></div>
<link rel="stylesheet" href="//embed.typeform.com/next/css/widget.css" />
<script src="//embed.typeform.com/next/embed.js"></script>
<script>
  function loadMyHiddenFields(callback) {
    fetch('/api/hidden-field')
      .then(res => res.json())
      .then(callback)
  }
  function initTypeform(data) {
    window.tf.createWidget('<form-id>', {
      container: document.getElementById('wrapper'),
      hidden: { myHiddenField: data.value },
    })
  }

  loadMyHiddenFields(initTypeform)
</script>

 

View original

4 replies

Liz
Exโ€“Typefomer
Forum|alt.badge.img+5
  • Tech Community Advocate
  • 15035 replies
  • March 25, 2022

Hi @AurelienB Could you send the URL where you have the form/script so we can take a look at your set up? Thanks!

@mathio may also be able to help with this one


  • Author
  • Explorer
  • 1 reply
  • March 26, 2022
Liz wrote:

Hi @AurelienB Could you send the URL where you have the form/script so we can take a look at your set up? Thanks!

@mathio may also be able to help with this one

 

Hi @Liz hope youโ€™re doing well.

Hereโ€™s an example of my typeform with an hidden field and the javascript loading on the page.

But Iโ€™m struggling to put in because the code loads after the typeform html.

 

https://sms-s.fr/type.html

 

Thanks by advance


Liz
Exโ€“Typefomer
Forum|alt.badge.img+5
  • Tech Community Advocate
  • 15035 replies
  • March 28, 2022

Thanks @AurelienB ! In the URL, I donโ€™t see an option for a hidden field. How is it being passed through the Javascript? Iโ€™m not seeing that either (though I could be completely missing it). 


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

Hello @AurelienB 

you will need to use out embed SDK to embed your typeform asynchronously when your hidden field value is available. You can use JavaScript code like this one:

<div id="wrapper"></div>
<link rel="stylesheet" href="//embed.typeform.com/next/css/widget.css" />
<script src="//embed.typeform.com/next/embed.js"></script>
<script>
  function loadMyHiddenFields(callback) {
    fetch('/api/hidden-field')
      .then(res => res.json())
      .then(callback)
  }
  function initTypeform(data) {
    window.tf.createWidget('<form-id>', {
      container: document.getElementById('wrapper'),
      hidden: { myHiddenField: data.value },
    })
  }

  loadMyHiddenFields(initTypeform)
</script>

 


Reply