How to merge multiple Memberstack fields into one Webflow input field? Answered
I am trying to find a way to combined two Memberstack 2.0 fields to fill in a single Webflow input.
For example, on a Webflow checkout Webflow has a single Name field, so I want to populate this with Memberstack's First Name + " " + Last Name fields.
Normally I use the attribute syntax to autofill fields, such as: data-ms-member="first-name", but am not sure how that works for two fields in one.
Any help appreciated!
Comments
5 comments
Springthrough Consulting
Here's how you can combine the First Name and Last Name fields and populate a single Webflow input field:
Step 1: Set Up Your Webflow Input Field
In your Webflow project, give the single Name field an ID (e.g., `name-input`).
Step 2: Add Custom JavaScript
Add the following script to your Webflow project:
1. Go to your Webflow project settings.
2. Navigate to the Custom Code section.
3. In the Before </body> tag area, add the following script:
Step 3: Publish Your Changes
After adding the script, make sure to publish your Webflow site to see the changes take effect.
Explanation of the Code
- The script waits for the DOM to fully load before executing.
- It uses `window.$memberstackDom.getCurrentMember()` to retrieve the current member's data.
- It accesses the First Name and Last Name from the `customFields` object and combines them into a single string.
- Finally, it sets the value of the input field with the combined name.
Important Note
Make sure to replace `'name-input'` in the script with the actual ID of your input field in Webflow.
This code will effectively autofill the Name field with the combined First Name and Last Name from Memberstack.
Great question! This sounds like it would be a good Memberscript.
I'll share with Julian and see what we can do 😁
I asked Claude for help 😁
Here's how to use this script:
modifiedUrl
line in the script accordingly.This script does the following:
window.$memberstackDom.getCurrentMember()
to get the current member's data.Yes, you can definitely get the login redirect URL using the method I've shared. Here's how you can achieve that:
loginRedirect
URL.href
attribute.Here's a modified version of your code to handle this:
Make sure your button has the correct ID, and this should work as expected!
Chukwudi Onyekwere Thank you very much!!
I have one additional question that is kind of similar, so I will ask it here but if we need to open a second question that is totally fine!
My second question is that I am using Memberstack's Login Redirect Url on a Button (So in Webflow we launch the Memberstack widget, I click on a Button then in the Memberstack widget I scroll down to the Links/Actions section and choose the Login Redirect option for the Button's URL).
So the question is, are we able to get that Login Redirect URL in a similar method that you shared above and set it on a Button manually? I need to essentially tack a hash onto this URL, such a mywebsite.com/users/abdc123#Invoices and I am assuming I have to get/set that manually in a script as we cannot append any strings/values to the Login Redirect option.
Thank you!
Please sign in to leave a comment.