How to pass logged-in user data to embedded form

This code doesn’t work anymore because of “document.write()” being deprecated. Here is the updated code you guys should use:

→ Don’t forget to insert your tally form id under [FORM_ID]

<script>
  let tallyUrl = 'https://tally.so/embed/[FORM_ID]?hideTitle=1&transparentBackground=1&dynamicHeight=1';

  if (window['logged_in_user'] && window['logged_in_user']['record_id']) {
    tallyUrl = tallyUrl + '&record_id=' + encodeURIComponent(window['logged_in_user']['record_id']);
  }

  // Create the iframe element
  const iframe = document.createElement('iframe');
  iframe.src = tallyUrl;
  iframe.style.width = '100%';
  iframe.style.height = '500px';
  iframe.style.border = 'none';
  iframe.style.margin = '0';
  iframe.title = 'My Application';

  // Insert the iframe into the document
  document.currentScript.parentNode.insertBefore(iframe, document.currentScript.nextSibling);
</script>
1 Like