Submitting content from table to table

Alright - this may require an “expert” at Wix Code but I hope I will find someone.

So I have 2 Dynamic pages both connected to different tables inside my Database. One is a profile page and one is a form submission page. Now whenever the logged in User is on the Form submission they have to re-type their First Name, Last Name and Email address (so me on the other end knows who has submitted a form) even though they already have a profile. This is annoying for the client to deal with and inconvenient.
What lines of code do i use in order for these 3 fields to pull the information from the Profile page table automatically and when submitted show up in the Sumbission from table?

Hope this makes sense

Thanks in advance

Daniel

1 Like

Hey Daniel,

Welcome to the Wix Code forums.

In the page’s onReady() function, you can do a query of the user database to retrieve the user’s information. Then set the appropriate fields in the form using the retrieved information.

Yisrael

1 Like

This is what i got but somehow when the user submits it it still doesnt fill into the table in the database. What am i doing wrong?

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady(function () {
wixData.query(“PROFILE”)
.eq(“_id”, wixUsers.currentUser.id)
.find()
.then((result) => {
if(result !== null && result.items.length > 0) {
var user = result.items[0];

		$w("#contactFirstName").value = user.firstName; 
		$w("#contactLastName").value = user.lastName; 
		$w("#contactEmail").value = user.email; 
	} else { 
		// Couldn't find user 
	} 
}); 

});

Do the fields get filled in with the data from the query?
Are those fields connected to the dataset?

1 Like

Hey Yisrael - firstly, thanks for all your help.

The fields are connected to the submission dataset (where i want the submitted form to show up) and the dynamic page is connencted to the Profile dataset.

In regards to the query, when I load the page for the first time as a user then i does autopopulate the data from the query just like i want it to. However once this form is submitted it goes back to the generic “first name” “last name” etc. and it also does not send the actual name to the table.

Really puzzeling

Post your URL here and I’ll look at it as soon as I can.