Reloading use data after it has been submitted without reloading page

Very new to Corvid!

I have a user form that fills in the data from the users using the following code. The page this form is on is only available when you are logged in.

import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
	//TODO: write your page related code here...

	// ...
	let user = wixUsers.currentUser;
	let userId = user.id;
	let isLoggedIn = user.loggedIn;
	let userRole = user.role;
	user.getEmail()
		.then((email) => {
			let userEmail = email; // "user@something.com" 
			$w('#input10').value = userEmail;
			$w('#input7').value = userEmail;
		});

	$w.onReady(function () {
		wixData.query("Members/PrivateMembersData")
			.eq("_id", wixUsers.currentUser.id)
			.find()
			.then((results) => {
				$w('#input12').value = results.items[0].firstName;
				$w('#input9').value = results.items[0].firstName;
			});
	});

	$w.onReady(function () {
		wixData.query("Members/PrivateMembersData")
			.eq("_id", wixUsers.currentUser.id)
			.find()
			.then((results) => {
				$w('#input11').value = results.items[0].lastName;
				$w('#input8').value = results.items[0].lastName;
			});
	});

});

I have hidden the input boxes so the user does not see this. When the press the submit button (using the code below) the input values are in the input boxes.

export function button11_click(event) {
	//Add your code for this event here: 
	
		$w('#textBox1').collapse();
	
		$w('#button11').collapse();
	
		setTimeout(function () {
			$w("#columnStrip9").collapse();
		}, 3000);

		setTimeout(function () {
			$w("#columnStrip8").collapse();
		}, 3000);


		setTimeout(function () {
			$w("#columnStrip6").expand();
		}, 3000);

		setTimeout(function () {
			$w("#columnStrip10").collapse();
		}, 3000);

}

All is working fine. But when the user adds new data to the textBox1 and re-submits the values of their firstname, lastname, and email are not copied. I understand this is because it puts these values in when loading the page with the onReady function.

How do I change the code so that the data is placed in the right place when re-submitting the data?
Really cant figure this out!

Some background information.

It is a ‘ask a question’ box below a livestream video playing above it. The questions dont need to be answered right away but should be available later one.

Thanks already! This forum has gotten me as far as writing this code :slight_smile:

If you submit to a dataset or to your collection it’ll be easier.
But if you use one of the ready-made Wix forms, you’ll need to use a workaround:
For example, once the success message appears you can reassign the values to the hidden inputs. something like:

let firstName = "John", lastName = "Doe";
$w("#successMessage").onViewportEnter(() => {
    $w("#input1").value = firstName;
    $w("#input2").value = lastName;
})

First of all, I suspect that you’re getting a permission error on the live site because you’re querying a read-only collection for site-member author only, to get the user details, you need to query the collection from the backend and pass it the user ID, and pass the SupressAuth a true value to the query’s .find() function, then return the result to the frontend code.