Pass a member email at the upload of a file Answered

Hey team,

I would like to pass a member email at the upload of a file:

I wrote the following code and works well. What attribute shall I add if I want to pass also the email?
Thank you in advance for any help!

<!-- :blue_heart: MEMBERSCRIPT #38 v0.1 :blue_heart: FORM FILE UPLOADER --> <script> window.$memberstackDom.getCurrentMember().then(({ data: member }) => { if (member) { let id = member.id // do something with the id const forms = document.querySelectorAll('form[ms-code-file-upload="form"]'); forms.forEach((form) => { form.setAttribute('enctype', 'multipart/form-data'); const uploadInputs = form.querySelectorAll('[ms-code-file-upload-input]'); uploadInputs.forEach((uploadInput) => { const inputName = uploadInput.getAttribute('ms-code-file-upload-input'); const fileInput = document.createElement('input'); fileInput.setAttribute('accept', '.csv') fileInput.setAttribute('type', 'file'); fileInput.setAttribute('name', inputName); fileInput.setAttribute('id', inputName); fileInput.setAttribute('memberid', id); //fileInput.required = true; // delete this line to make the input optional uploadInput.appendChild(fileInput); }); }); } }) </script>

Comments

2 comments

  • Comment author
    A J

    Hey Luca De Angelis, you can include something like this in the script to get the email ID.

    window.$memberstackDom.getCurrentMember().then((member) => {
    if (member.data) {
    var emailID = member.data.auth.email;
    }
    })

    Since you already have the function probably just include

    var emailID = member.data.auth.email;

    after the comment '// do something with the id' and this will fetch the logged-in member's email and you can now use the email for your use-case.

    In case you want to pass it on as a hidden field with the form, a simpler way could be to make use of something like this in the form block as HTML embed:

    <input type="hidden" name="Email" data-ms-member="email">

    Hope this helps.

    0
  • Comment author
    Luca De Angelis

    Thanks! I'll try that 🙂

    0

Please sign in to leave a comment.