This feature is super handy when linking from an email to your signup, login, or password reset forms. Since you already know the member's email address it's only kind to pre-fill that email when they land on the page.
You'll want to add this code to the Footer or <Body> section of any page with a signup, login, or reset password form.
<script type="module">
import * as queryString from "https://cdn.jsdelivr.net/npm/native-querystring@1.1.1/+esm";
function prefillInputsByDataAttribute(dataAttribute) {
const params = queryString.parse(window.location.search);
const elements = document.querySelectorAll(`[${dataAttribute}]`);
elements.forEach(element => {
if (element.tagName === "INPUT") {
element.value = params["ms-email"] || "";
}
});
}
window.$memberstackDom.getCurrentMember()
.then(({ data: member }) => {
prefillInputsByDataAttribute("data-ms-member=email");
});
</script>
The link param should look something like this:
www.yourdomain.com/login?ms-email=email@gmail.com
.
Comments
3 comments
Memberstack Team
If the snippet doesn't work, add:
In your opening script :)
Thank you Massak Chrait 🙏
btw - how did you get the code element to appear in your comment? I've been struggling to figure that out! haha
Duncan Hamra
Please sign in to leave a comment.