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

@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!

@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.

This worked fine for me for a couple of months (until September 2022) but since October the replacement of the email in links via the header code injection stopped working; @artur can you pls confirm whether any changes might have been made in the backend to any of the variables used in your code snippet that might be the reason why it stops replacing the email correctly now? thx, Stephan