Create form that member can update

I am trying to create a form that each member can submit. Also, when the member returns to the form, it should still display the data from their last input. Basically, a form that the user can update.

here is my code currently:

// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import wixLocation from ‘wix-location’;
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’

// Auto-Fill Form
$w.onReady( function () {
$w(“#input1”).value = $w(‘#dataset1’).getCurrentItem().firstName;
$w(“#input2”).value = $w(‘#dataset1’).getCurrentItem().lastName;
$w(“#input3”).value = $w(‘#dataset1’).getCurrentItem().email;
$w(“#input4”).value = $w(‘#dataset1’).getCurrentItem().list1;
$w(“#input5”).value = $w(‘#dataset1’).getCurrentItem().list2;
$w(“#input6”).value = $w(‘#dataset1’).getCurrentItem().list3;
});

// Submit Auto-Filled Items
export function Submit_click(event, $w) {
$w(‘#dataset1’).setFieldValue(‘fname’, $w(‘#input1’).value);
$w(‘#dataset1’).setFieldValue(‘lname’, $w(‘#input2’).value);
$w(‘#dataset1’).setFieldValue(‘email’, $w(‘#input3’).value);
$w(‘#dataset1’).setFieldValue(‘list1’, $w(‘#input4’).value);
$w(‘#dataset1’).setFieldValue(‘list2’, $w(‘#input5’).value);
$w(‘#dataset1’).setFieldValue(‘list1’, $w(‘#input6’).value);
}

#members #autofill #form #updateform #getCurrentitem #getCurrent

Something similar for members profile page is already setup in a Wix tutorial. Have a look and use the code as a starting point.

this is helpful, but i need to be able to have the form blank when a user sees the form for the first time, but then populated after they fill out some boxes. that link assumes the data is already stored when they reach the form

or at least the user id for the form is already stored


import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import wixData from 'wix-data'

$w.onReady(function () {
 
//check the current user's email using getEmail()
let user = wixUsers.currentUser;

user.getEmail()
  .then( (email) => {
 let userEmail = email;      // "user@something.com"
  } );

//query the mylist dataset
wixData.query("mylist")
  .eq("email")
  .find()
  .then( (results) => {
 
 //if the dataset does NOT have the email, then make the inputs fields blank since this is their first time submitting
 if(userEmail NOT "email"){
        $w('#input1').value = undefined
        $w('#input2').value = undefined
        $w('#input3').value = undefined
        $w('#input4').value = undefined
        $w('#input5').value = undefined
        $w('#input6').value = undefined
    }
  } )
  .catch( (err) => {
 let errorMsg = err;
  } );

i currently have a filter on my dataset for logged in user. that is why i am trying to create code to display the inputs as blank if this is the first time the user is filling out the form. otherwise, with the filter you won;t be able to input anything because there is no data for the logged in user yet

Patrick sorry I didn’t go in deep but why don’t you control every data without filter but only with code ? In this way you’ll get the total control.

@mauro-vento-avyno ok i tried taking off the filter and just checking the user email is in the dataset. then populating the input fields if it is. i’m getting errors in this code:

import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import wixData from 'wix-data'

$w.onReady(function () {


//check the current user's email using getEmail()
let user = wixUsers.currentUser;

user.getEmail()
  .then( (email) => {
 let userEmail = email;      // "user@something.com"
  } );

//autofill the email into the dataset
$w("#input3").value = userEmail;


//query the mylist dataset
wixData.query("mylist")
  .eq("email")
  .find()
  .then( (results) => {
 
 //if the dataset has the user's email then set the user info to each input
 if (userEmail === results) {
 
 
  $w("#input1").value = $w('#dataset1').getCurrentItem().firstName;
  $w("#input2").value = $w('#dataset1').getCurrentItem().lastName;
  $w("#input3").value = $w('#dataset1').getCurrentItem().email;
  $w("#input4").value = $w('#dataset1').getCurrentItem().list1;
  $w("#input5").value = $w('#dataset1').getCurrentItem().list2;
  $w("#input6").value = $w('#dataset1').getCurrentItem().list3; 
  }
  })

  } )
  .catch( (err) => {
 let errorMsg = err;
  } );


It will be blank if you have only collected the email, password and first and last name of the user on your signup form.

The email and password will be saved into the Wix CRM which you will be able to see the email and first and last name in the Contacts list on your Dashboard.

If you have the Wix Members app added to your site already too, then you have the Members/PrivateMembersData collection.
https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields

The first time that the member sees their own member profile page, then it will only show their first and last name as that is the only thing that would be stored in your members dataset.

Then the member can add or edit anything on their member profile page by clicking on the update button which will take them to their update member profile page.

Once the member adds, edits or changes anything on their update member profile page and clicks on submit or save, whatever button you used, then those user inputs will be saved into the members dataset and will then be displayed on the members profile page.

Hence why you have the two dynamic member pages, one for the members profile which displays the members info from the members dataset, with the update members profile page being the one members use to edit or add any of their details which is then saved and updates anything in the members dataset again.

The Wix Members app have a similar My Account page that you can use too.
https://support.wix.com/en/article/about-members-area

ID field for Members/PrivateMembersData collection is the same as the Owners field on all other datasets, this is the best field to use as it will be exactly the same for each dataset.

I’ll control your code, but at first I don’t believe “userEmail === results” will work.

Perhaps you’ll have to use ‘results.items[0].email’ or something similar.

I’d control getting a console.log on the ‘results’.

More, look at ‘eq’ reference, you need 2 elements:
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#eq

let options= {suppressAuth:true, suppressHooks:true}

//query the mylist dataset
wixData.query("mylist", options)
  .eq("email", email)
  .find()
  .then( (results) => {
         if (userEmail === results.item[0].email) {....

@givemeawhisk Thank you for this explanation!