carg
August 26, 2024, 6:46am
1
I recently had a problem that when I put tally code in softr, it goes under the footer.
It’s not always an error with external code, but it seems to be a policy change in certain code.
It’s a code that matches the hidden field created in tally with the login information in softr.
I found this code by googling, but I don’t know where it came from.
The code itself is fine, but softr doesn’t seem to be accepting it properly, is there any way to fix it?
<script>
const tallyUrl = 'https://tally.so/embed/탈리 고유 주소.....: ?alignLeft=1&hideTitle=1&alignLeft=1';
const recordId = getUrlParam('recordId');
console.log(recordId);
const iframe = document.createElement('iframe');
iframe.width = '100%';
iframe.height = '1200px';
iframe.frameBorder = '0';
iframe.marginHeight = '0';
iframe.marginWidth = '0';
iframe.title = 'TITLE';
if (window.logged_in_user?.softr_user_email) {
const hiddenFields = new URLSearchParams({
user_email: window.logged_in_user.softr_user_email,
user_full_name: window.logged_in_user.softr_user_full_name,
user_record_id: window.logged_in_user.airtable_record_id,
page_record_id: recordId
});
iframe.src = `${tallyUrl}&${hiddenFields}`;
} else {
iframe.src = tallyUrl;
}
document.body.appendChild(iframe);
function getUrlParam(name) {
const url = new URL(window.location.href);
const param = url.searchParams.get(name.toLowerCase());
return param || (name.toLowerCase() === 'recordid' ? getRecordIdFromPath() : undefined);
}
function getRecordIdFromPath() {
const pathName = window.location.pathname;
const recIndex = pathName.indexOf('/r/rec');
if (recIndex !== -1) {
const recordIdPath = pathName.slice(recIndex + 3);
return recordIdPath.split('/')[0];
}
}
</script>
Hi,
This code won’t work properly I think,
Try with this syntax, added in a custom code block (to be adapted)
<div id="custom-code-block">
<!-- Placeholder for the iframe -->
<div id="tally-embed-placeholder"></div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
let tallyUrl = 'https://tally.so/embed/xxxxx?alignLeft=1&hideTitle=1&transparentBackground=1&dynamicHeight=1'; // replace with your own tally embed url
if (window.logged_in_user && window.logged_in_user.record_id) {
tallyUrl += '&user_record_id=' + window.logged_in_user.record_id;
} // add email param and full name param if necessary
let iframe = document.createElement('iframe');
iframe.setAttribute('data-tally-src', tallyUrl);
iframe.setAttribute('loading', 'lazy');
iframe.setAttribute('width', '100%');
iframe.setAttribute('height', '603');
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('marginheight', '0');
iframe.setAttribute('marginwidth', '0');
iframe.setAttribute('title', 'Any Title');
const placeholder = document.getElementById('tally-embed-placeholder');
if (placeholder) {
placeholder.appendChild(iframe);
}
var d = document,
w = "https://tally.so/widgets/embed.js",
v = function() {
if (typeof Tally !== "undefined") {
Tally.loadEmbeds();
} else {
d.querySelectorAll("iframe[data-tally-src]:not([src])").forEach(function(e) {
e.src = e.dataset.tallySrc;
});
}
};
if (typeof Tally !== "undefined") {
v();
} else if (d.querySelector('script[src="' + w + '"]') == null) {
var s = d.createElement("script");
s.src = w;
s.onload = v;
s.onerror = v;
d.body.appendChild(s);
}
});
</script>
Also, what does not work exactly? The tally form is being displayed correctly? Some hidden parameters are missing when filling out the tally form?
carg
August 26, 2024, 7:24am
5
NOTE: the code below is outdated please use this version from @StevenS
If the embedded form supports passing data by url then one can use a code similar to this one to pass currently logged in user info to the form:
<script>
let tallyUrl = 'https://tally.so/embed/urlHash?hideTitle=1&alignLeft=1';
if(window['logged_in_user'] && window['logged_in_user']['airtable_record_id']) {
tallyUrl = tallyUrl + '&record_id=' + window['logged_in_user']['airtable_record_id'];
}
docu…
I found the answer in this article.
I’ll try again and let you know the results.
Ok,
Note that the outdated part mentioned in the other thread concerns document.write() which is deprecated.