Add pre-set data to inputs

Hey everyone,

I have created a site to allow people to create accounts and donate items.

When you create an account, you can access your profile, to add more info like phone number and address.

At the moment, each time you want to donate an item, you would have to fill in the details again.

Is there a way to pre-fill the fields according to the data you enterd in the profile page?

Here is the site: profile-test-site

There are at least two ways to do this, with lots of other potential variations:
For the sake of this example, and based on what I think I saw on your site - I’m assuming the site requires the users to log in first and become site members.

Method 1 - (I haven’t tested this personally but it should work)

  • Presumably, you’re saving the profile data to a Wix Code database collection.

  • You want to make sure the permissions on the user profile collection are such that the only the data owner can read the records they created. That means users will only be able to fetch the database records they created, and therefore not see other users’ data. Learn about permissions here

  • That helps you in an unexpected way though - because now if you create a dataset on the donation page looking at the profile collection - the only record that will come back is the one associated with the logged in user.

  • Now - when using that data you’re in a bit of a pickle, because you’ll want to connect the input components to the profile data to read it from there, but on the other hand you’ll want to connect them to the donations collection to save it. You can’t do that, so you’ll need to use JavaScript for one of the directions. Let’s assume you want to do the saving in JavaScript - use the donation dataset’s setFieldValue function for that.

Method 2 - Saving in the browser’s local storage
The browser’s local storage is a way for you to save information in the user’s browser data (similarly to what cookies do). Using the local storage, you could save the profile information and use it to pre-populate the input fields. You can find out more here

Good luck!