Pass airtable data to custom block code using fillout form

Hi team. Could you help get data from specific fields on airtable to a custom block?

I am using a code to recognize airtable user ID and pass to a fillout form.

<div style="width:100%;height:500px;" data-fillout-id="wtjH1tfWmCus" data-fillout-embed-type="standard" data-fillout-inherit-parameters data-fillout-dynamic-resize></div>
<script>
document.querySelectorAll("[data-fillout-id]:not([data-fillout-id=\"\"])").forEach((target) => {
    if (window.logged_in_user && window.logged_in_user.softr_user_email) {
        target.setAttribute("data-email", window.logged_in_user.softr_user_email);
        target.setAttribute("data-name", window.logged_in_user.softr_user_full_name);
        target.setAttribute("data-id", window.logged_in_user.airtable_record_id);

    }
});
</script>
<script src="https://server.fillout.com/embed/v1/"></script>

Now I need to get data from a other airtable fields. For example the field status under “contacts” table on airtable

Also I need to get a record ID from a detailed page where the form is embed. There is a list detail block in the same page I have the custom code block. The ID I need is called “ID evento” under “eventos” table" . is the same ID from the Page URL as we are in a detailed page.

Can you help me finish this code?

thanks

To display data from other table than ‘users’ , simply add the table to your page and map the needed values in this new block. Then hide it with css. Now the values for that record can be accesed from the window.records object. And then can be placed anywhere on your page, or can be passed as parameters to your fillout form.

Also accesing the record id in your url can be done with some code like:

<script>
        let pageUrl = new URL(window.location.href);

        let id = pageUrl.searchParams.get("recordId");

        let filloutUrl = 'https://form.fillout.com/t/xxxxxxxxus?' + 'id=' + id;

        if(window['logged_in_user'] && window['logged_in_user']['softr_user_email']) {
            filloutUrl = filloutUrl + '&email=' + window['logged_in_user']['softr_user_email'];
            filloutUrl = filloutUrl + '&name=' + window['logged_in_user']['softr_user_full_name'];
            filloutUrl = filloutUrl + '&userid=' + window['logged_in_user']['airtable_record_id'];        }

        document.write('<iframe src="' + filloutUrl + '" width="100%" height="1200px" frameborder="0" marginheight="0" marginwidth="0" title="Actualizar recibo" id = "editarrecibo" scrolling="no"></iframe>');
    </script>
1 Like

Thanks for replying Jonathan.

I am not sure how to use window.records object

If the record ID i need is in the table called “eventos” and the filed for this record ID is called “ID evento” how should the code be?

Ok, I thought that record id you needed it was listed in the url.

First you must have listed on the details page the value that you expect to grab.
It can be hidden with css but it must rendered so we can access it.

Then you can try this:

<script>
// Get record field values to map them into section 
    const wait = setInterval(function () {
        if (window.records !== undefined) {
            clearInterval(wait);
            document.getElementById("service-name").innerText = window.records[Object.keys(window.records)[0]].record.fields['Service name'];
            document.getElementById("service-description").innerText = window.records[Object.keys(window.records)[0]].record.fields['Service description'];           
        }
    },1000)

</script>

<!--Now lets show the dynamic values into page -->

<div id= 'service-name'></div>
<div id= 'service-description'></div>

Thanks Janathan. Now i cannot understand anything lol. SOrry, I am not technical.

The code below is what is working right now. I am retrieving user id , email and name. I need to retrieve the record ID from table (eventos). This ID is also in the URL because is a detailed list.

<div style="width:100%;height:500px;" data-fillout-id="gaAEu9Vb48us" data-fillout-embed-type="standard" data-fillout-inherit-parameters data-fillout-dynamic-resize></div>
<script>
document.querySelectorAll("[data-fillout-id]:not([data-fillout-id=\"\"])").forEach((target) => {
    if (window.logged_in_user && window.logged_in_user.softr_user_email) {
        target.setAttribute("data-email", window.logged_in_user.softr_user_email);
        target.setAttribute("data-name", window.logged_in_user.softr_user_full_name);
        target.setAttribute("data-id", window.logged_in_user.airtable_record_id);

    }
});
</script>
<script src="https://server.fillout.com/embed/v1/"></script>```

HI Jonathan, I have replaced my code with yours abd now all data I need is retrieving. thanks a lot! Now I am able to get any variable from the user table and also the page URL Id

    <script>
        let pageUrl = new URL(window.location.href);

        let id = pageUrl.searchParams.get("recordId");

        let filloutUrl = 'https://form.fillout.com/t/gaAEu9Vb48us?' + 'id=' + id;

        if(window['logged_in_user'] && window['logged_in_user']['softr_user_email']) {
            filloutUrl = filloutUrl + '&email=' + window['logged_in_user']['softr_user_email'];
            filloutUrl = filloutUrl + '&name=' + window['logged_in_user']['softr_user_full_name'];
            filloutUrl = filloutUrl + '&IDuser=' + window['logged_in_user']['airtable_record_id'];
            filloutUrl = filloutUrl + '&Status=' + window['logged_in_user']['Status'];    }

        document.write('<iframe src="' + filloutUrl + '" width="100%" height="1200px" frameborder="0" marginheight="0" marginwidth="0" title="Actualizar recibo" id = "editarrecibo" scrolling="no"></iframe>');
    </script>```

Hi Jonathan, do you use whatsApp? or whats your email?

@acjnas document.write is not the right way to inect I would rather have a container div element and then append iframe into that div via the following code like snippet

<div id="targetDiv"></div>
<script>
        // Select the div where you want to insert the iframe
        var targetDiv = document.getElementById('targetDiv');

        // Create the iframe element
        var iframe = document.createElement('iframe');

        // Set the attributes for the iframe
        iframe.setAttribute('src', 'https://www.example.com');
        iframe.setAttribute('width', '600');
        iframe.setAttribute('height', '400');
        iframe.setAttribute('frameborder', '0'); // Optional: Set to 0 for no border
        iframe.setAttribute('allowfullscreen', 'true'); // Optional: Allow full screen

        // Append the iframe to the selected div
        targetDiv.appendChild(iframe);
    </script>

Good day all.

I was sent here by Softr support, but have MANY questions (and this code isn’t working for me). I had a working page built in Softr (working for over 6 months). I was successfully using Fillout form.

My page had (in this order):

  • the header then
  • a text block then
  • a form embedded using custom code block with iframe then
  • a footer
    Suddenly 2 days ago I woke up and all my pages with forms (not just Fillout forms, but Tally.so forms as well), ALL my pages suddenly moved the form portion to below the footer. I did not make any changes in the forms or my Softr pages. FYI the page still works, the form works only to position of the form has moved to below the footer.

Does anyone have any ideas why suddenly my forms are all below my footer? More importantly, how do I fix this? Softr support is saying “Fillout form issue” but I am skeptical as this is happening with all forms (not just Fillout).

I hope someone can help or at least point me in the right direction. I have been a long time PAID CUSTOMER of Softr, but if the platform can’t be stable and provide EXCELLENT SUPPORT, I am being forced to move my business elsewhere.

Here is the code I have been using to embed my Fillout form:

let filloutUrl = ‘https://xxxxxxxx.yyyyyyyyy.com/t/zzzzzzzzzzzzz?’;

if(window[‘logged_in_user’] && window[‘logged_in_user’][‘softr_user_email’]) {
filloutUrl = filloutUrl + ‘email=’ + window[‘logged_in_user’][‘softr_user_email’];
filloutUrl = filloutUrl + ‘&name=’ + window[‘logged_in_user’][‘softr_user_full_name’];
filloutUrl = filloutUrl + ‘&id=’ + window[‘logged_in_user’][‘airtable_record_id’];
}

document.write(‘’);

1 Like

Hi @artur,

FYI, One of my clients has exactly the same problem (with Tally embedded form)

Thank you, hopefully this gets someone’s attention. I am a bit frustrated with the quick “it’s not our fault” reply from Softr support.

Hey @TeaDrinkingHacker I will be more than glad to help you with this! I already found your app where you contacted us yesterday, all we need to do is the adopt the method mentioned above by Artur which was Using document.write for injecting content is not recommended due to its potential to overwrite the entire document and cause performance issues. Instead, it is better to use a container div element and append an iframe into that div. I DM-ed you the proper code just simply please change it with the one you have.

Best regards,

2 Likes

@Andranik Solved for my client, the customer service made it… I didn’t read Artur’s post above :sweat_smile: sorry

1 Like

Going to test right now and will report back. Thank you VERY much for the help @Andranik

Your code has worked @Andranik THANK YOU, THANK YOU, THANK YOU.

Happy to hear it worked.

document.write is heavily discouraged