Pass Logged In User info to URL in List Button?

Is there a way to pass user’s email or name through to URLs? example of what I’d like to happen: formexample.com/prefill_Email={LOGGED_IN_USER:EMAIL}]

My use-case: I am using miniExtension links to automatically register people for events when they click a button in a list. I am able to pass the event name to the miniextension form through the table that is linked to the list, but have yet to figure out how to auto-populate the logged in user’s information. The form is not an embedded form, but rather the button is an external link-out to the form.

Thank you for any help!

Hi there

Im just doing the same, and support have pointed me to this article - not yet got it working though. Searching to sort it too!

@alinasig and @howlec The script here, if added into page settings custom code header area will replace {LOGGED_IN_USER:EMAIL} text with user’s email address in the links

<script>
    document.addEventListener("DOMContentLoaded", function () {
        var exitCondition = setInterval(function() {
            $('a').each(function() {
                if($(this).attr('href') && $(this).attr('href').includes('{LOGGED_IN_USER:EMAIL}')) {
                    const userEmail =  window['logged_in_user']['softr_user_email'];
                    const url = $(this).attr('href').replace('{LOGGED_IN_USER:EMAIL}', userEmail);
                    $(this).attr('href', url);
                }
            });
        }, 600);
    });
</script>

1 Like

Hi Artur. Thanks. Im really close but still not there…

I’ve used the embed code from Airtable for the form, and added the prefill code that airtable needs, as {LOGGED_IN_USER:EMAIL}

Then I’ve put the code you’ve given in the header area of the page that the form is embedded on.

The form is pre-filled but remains {LOGGED_IN_USER:EMAIL} as text and isn’t replaced - and is entered as {LOGGED_IN_USER:EMAIL} into Airtable.

Im obviously not taking the right approach! Can you point in the right direction please

Howard

1 Like

@artur would you be able to help more!

@howlec this one is not related to embeds for embed check this link pls: How to pass logged-in user data to embedded Airtable form

This worked like a charm. Thank you, @artur!

Hi Softr team,

I would like to pass the record id in a button URL (from a list detail page).
How can I adapt the code to get the record id instead of user’s email ?

Thanks in advance for your help

Dear @Elise,

You can have a form in List Details page add a hidden field with Record ID and leave only the button. This way you will be able to grab the record ID.

https://docs.softr.io/building-blocks/form/custom-form#hidden-field

Thanks,

Hi @Suzie ,
Thanks a lot for your answer.
I thought about this solution, but it does not work in my particular case.
Actually, i would like to create a learning peer system :

  1. Each user can create his list of “learning journeys”, in his profile.
  2. The user can access to a list of peers.
  3. The user can select a peer. In the peer detail page, the user will have the choice to contact the peer for one of his own “learning journey”.

So, the goal is to get both : the ID of the “learning journey” AND the ID of the peer (the List Details page)

Thanks in advance for your help :slight_smile:

Dear @Elise,

Do you mean you want a logged in user to login and create a list of Learning Journey?

Thanks!

1 Like

@artur This is very helpful, thank you. How would I modify the script to replace {LOGGED_IN_USER:NAME} with the user’s name, too?

@artur, to be more clear, I wish to replace both variables in the following URL with the logged in user’s email and full name, respectively:

https://www.videoask.com/00000000#contact_email={LOGGED_IN_USER:EMAIL}&contact_name={LOGGED_IN_USER:NAME}

I figured out a way, but likely not the best way, to accomplish my goal. I’m new to Javascript, so this is a bit of a hack:

         ...
            $('a').each(function() {
                if($(this).attr('href') && $(this).attr('href').includes('{LOGGED_IN_USER:EMAIL}')) {
                    const userInfo =  window['logged_in_user']['softr_user_email'] + '&contact_name=' + window['logged_in_user']['softr_user_full_name'];
                    const url = $(this).attr('href').replace('{LOGGED_IN_USER:EMAIL}', userInfo);
                    $(this).attr('href', url);
                }
          ...

dbayless, thanks much, this was very helpful for me. I need to pass userID when calling a Tally pop-up Form from buttons on both CTA blocks and List Details blocks. Your code from a few weeks ago allows that without having to call a stand-alone page just for a script. If I have to call a separate page for a script it kind of defeats the purpose of a pop-up. I can put the userID right into the static URL from a CTA button. At least it worked on one page, but now it doesn’t seem to work anymore from a different page! (Put your code into site-wide footer). Maybe an issue with timing before full page load? Not sure.

However, it doesn’t seem to work on a List Details block when the button is calling a URL from an Airtable Field, there seems to be no way to call a static URL from a List Details button it seems. And your code doesn’t seem to affect the href link brought back from Airtable for the button press. Any thoughts from anyone?

1 Like

Really good question, I am having a similar problem.

Hi there,

I’ve successfully managed to pass logged in user info to a Tally URL, thanks to your recommendation @artur :ok_hand:

It worked for user names, recordID and emails but I am struggling to find a way to make it work for other Airtable fields as well. In my Airtable user table, there are two fields I would like to include in the script - “City” and “School” - but it’s not working.

Here is the code I used:

<script async src="https://tally.so/widgets/embed.js"></script>

<script>
    //Hidden fields Tally forms
    document.addEventListener("DOMContentLoaded", function () {
        var exitCondition = setInterval(function() {
            $('a').each(function() {
                if($(this).attr('href') && $(this).attr('href').includes('{U_RECORDID}')) {
                    const userRecordID =  window['logged_in_user']['airtable_record_id'];
                    const url = $(this).attr('href').replace('{U_RECORDID}', userRecordID);
                    $(this).attr('href', url);
                }
                if($(this).attr('href') && $(this).attr('href').includes('{U_EMAIL}')) {
                    const userEmail =  window['logged_in_user']['softr_user_email'];
                    const url = $(this).attr('href').replace('{U_EMAIL}', userEmail);
                    $(this).attr('href', url);
                }
                if($(this).attr('href') && $(this).attr('href').includes('{U_NAME}')) {
                    const userName =  window['logged_in_user']['softr_user_full_name'];
                    const url = $(this).attr('href').replace('{U_NAME}', userName);
                    $(this).attr('href', url);
                }
                if($(this).attr('href') && $(this).attr('href').includes('{U_CITY}')) {
                    const userCity =  window['logged_in_user']['airtable_field_City'];
                    const url = $(this).attr('href').replace('{U_CITY}', userCity);
                    $(this).attr('href', url);
                }
                if($(this).attr('href') && $(this).attr('href').includes('{U_SCHOOL}')) {
                    const userSchool =  window['logged_in_user']['airtable_field_School'];
                    const url = $(this).attr('href').replace('{U_SCHOOL}', userSchool);
                    $(this).attr('href', url);
                }
            });
        }, 600);
    });
</script>

Does someone know how to fix this? It would help me a lot! :slight_smile:

Fixed, syntax was not good!

<script>
    //Hidden fields Tally forms
    document.addEventListener("DOMContentLoaded", function () {
        var exitCondition = setInterval(function() {
            $('a').each(function() {
                if($(this).attr('href') && $(this).attr('href').includes('{U_RECORDID}')) {
                    const userRecordID =  window['logged_in_user']['airtable_record_id'];
                    const url = $(this).attr('href').replace('{U_RECORDID}', userRecordID);
                    $(this).attr('href', url);
                }
                if($(this).attr('href') && $(this).attr('href').includes('{U_EMAIL}')) {
                    const userEmail =  window['logged_in_user']['softr_user_email'];
                    const url = $(this).attr('href').replace('{U_EMAIL}', userEmail);
                    $(this).attr('href', url);
                }
                if($(this).attr('href') && $(this).attr('href').includes('{U_NAME}')) {
                    const userName =  window['logged_in_user']['softr_user_full_name'];
                    const url = $(this).attr('href').replace('{U_NAME}', userName);
                    $(this).attr('href', url);
                }
                if($(this).attr('href') && $(this).attr('href').includes('{U_CITY}')) {
                    const userCity =  window['logged_in_user']['City'];
                    const url = $(this).attr('href').replace('{U_CITY}', userCity);
                    $(this).attr('href', url);
                }
                if($(this).attr('href') && $(this).attr('href').includes('{U_SCHOOL}')) {
                    const userSchool =  window['logged_in_user']['School'];
                    const url = $(this).attr('href').replace('{U_SCHOOL}', userSchool);
                    $(this).attr('href', url);
                }
            });
        }, 600);
    });
</script>

Thanx this worked very well for me when the url was opened in a tab, but… when i opened the url in a modal window it failed to replace ‘{FIELD}’ placeholder.

@artur @Theo - Do you know how to fix this?