Submitting form with pre-filled values

I’ve made a simple form where the user fills in a form, but the Email is pre-filled by the $w code before. When I Publish the website I can see the email address has been filled in, however the value doesn’t get submitted to the Collection.

If I remove the code “$w(”#email").value = userEmail;" and just fill in the field manually, it works fine, but that’s now how I need the site to be. Can anyone understand why pre-filled inputs aren’t working?

    user.getEmail()
        .then( (email) => {
            let userEmail = email;
            $w("#email").value = userEmail;
    } );

In your use case you need to use the Wix Data insert() API to insert the data into the database.

Thanks for the steer Shan. If I need to use the wixData.insert() function and provide an object with all the variables from my input fields, how do I provide the email address?

Using the example code in my initial post, I can’t seem to use the variable userEmail outside of the then().

Just put the code under the page’s onReady function

import wixUsers from 'wix-users';

$w.onReady(function(){
    let user = wixUsers.currentUser;
    user.getEmail()
    .then( (email) => {
        let userEmail = email;
        // rest of code
        $w("#email").value = userEmail;
    });
});

Then pick up the value from this input element when submitting

let toSubmit = {
	email: $w("#email").value
};
wixData.insert("databaseId", toSubmit);